2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
9 /******************************************************************************
13 Execute <script> [{<arguments>}]
25 Executes a script with DOS commands.
29 FILE -- file to execute
45 ******************************************************************************/
47 #include <proto/exec.h>
48 #include <dos/filesystem.h>
51 #include <proto/dos.h>
52 #include <proto/alib.h>
55 #define SH_GLOBAL_SYSBASE 1
57 #include <aros/shcommands.h>
59 AROS_SH1(Execute
, 41.1,
60 AROS_SHA(STRPTR
, ,NAME
,/A
,NULL
))
65 struct CommandLineInterface
*cli
= Cli();
72 from
= Open(SHArg(NAME
), FMF_READ
);
76 IPTR data
[] = { (IPTR
)SHArg(NAME
) };
77 VFPrintf(Error(), "EXECUTE: can't open %s\n", data
);
78 PrintFault(IoErr(), NULL
);
83 if (!cli
->cli_Interactive
)
94 __sprintf(tmpname
, "T:Tmp%lu%lu%lu%lu%d",
95 ((struct Process
*)FindTask(NULL
))->pr_TaskNum
,
96 ds
.ds_Days
, ds
.ds_Minute
, ds
.ds_Tick
, count
);
97 tmpfile
= Open(tmpname
, MODE_NEWFILE
);
98 } while (tmpfile
== NULL
&& IoErr() == ERROR_OBJECT_IN_USE
);
104 while((c
= FGetC(from
)) != -1 && FPutC(tmpfile
, c
) != -1);
112 "EXECUTE: error while creating temporary file\n");
123 while((c
= FGetC(cli
->cli_CurrentInput
)) != -1 && FPutC(tmpfile
, c
) != -1);
129 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
137 Close(cli
->cli_CurrentInput
);
138 if (AROS_BSTR_strlen(cli
->cli_CommandFile
))
139 DeleteFile(AROS_BSTR_ADDR(cli
->cli_CommandFile
));
142 LONG len
= strlen(tmpname
);
143 CopyMem(tmpname
, AROS_BSTR_ADDR(cli
->cli_CommandFile
), len
);
144 AROS_BSTR_setstrlen(cli
->cli_CommandFile
, len
);
147 cli
->cli_CurrentInput
= tmpfile
;
149 Seek(tmpfile
, 0, OFFSET_BEGINNING
);
154 we should try to open ":T", but since ":"
155 is not handled correctly yet, we just give up
158 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
167 cli
->cli_Interactive
= FALSE
;
168 cli
->cli_CurrentInput
= from
;