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
58 #include <aros/debug.h>
59 #include <aros/shcommands.h>
61 AROS_SH2(Execute
, 41.1,
62 AROS_SHA(STRPTR
, ,NAME
, /A
, NULL
),
63 AROS_SHA(STRPTR
, ,ARGUMENTS
, /F
, NULL
))
68 struct CommandLineInterface
*cli
= Cli();
75 from
= Open(SHArg(NAME
), FMF_READ
);
79 IPTR data
[] = { (IPTR
)SHArg(NAME
) };
80 VFPrintf(Error(), "EXECUTE: can't open %s\n", data
);
81 PrintFault(IoErr(), NULL
);
86 if (!cli
->cli_Interactive
)
97 __sprintf(tmpname
, "T:Tmp%lu%lu%lu%lu%d",
98 ((struct Process
*)FindTask(NULL
))->pr_TaskNum
,
99 ds
.ds_Days
, ds
.ds_Minute
, ds
.ds_Tick
, count
);
100 tmpfile
= Open(tmpname
, MODE_NEWFILE
);
101 } while (tmpfile
== NULL
&& IoErr() == ERROR_OBJECT_IN_USE
);
108 if (FPuts(tmpfile
, ".pushis\n") != -1)
109 while((c
= FGetC(from
)) != -1 && FPutC(tmpfile
, c
) != -1);
117 "EXECUTE: error while creating temporary file\n");
128 FPuts(tmpfile
, ".popis\n");
130 while((c
= FGetC(cli
->cli_CurrentInput
)) != -1 && FPutC(tmpfile
, c
) != -1);
136 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
144 Close(cli
->cli_CurrentInput
);
145 if (AROS_BSTR_strlen(cli
->cli_CommandFile
))
146 DeleteFile(AROS_BSTR_ADDR(cli
->cli_CommandFile
));
149 LONG len
= strlen(tmpname
);
150 CopyMem(tmpname
, AROS_BSTR_ADDR(cli
->cli_CommandFile
), len
);
151 AROS_BSTR_setstrlen(cli
->cli_CommandFile
, len
);
154 arguments
= SHArg(ARGUMENTS
);
157 s
= AROS_BSTR_ADDR(cli
->cli_CommandName
);
158 len
= strlen(arguments
);
160 AROS_BSTR_setstrlen(cli
->cli_CommandName
, len
+ 1);
161 CopyMem((APTR
)arguments
, s
, len
);
165 AROS_BSTR_setstrlen(cli
->cli_CommandName
, 0);
167 cli
->cli_CurrentInput
= tmpfile
;
169 Seek(tmpfile
, 0, OFFSET_BEGINNING
);
174 we should try to open ":T", but since ":"
175 is not handled correctly yet, we just give up
178 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
187 STRPTR arguments
= SHArg(ARGUMENTS
), s
;
192 kprintf("[Execute] args: %s\n", arguments
);
193 s
= AROS_BSTR_ADDR(cli
->cli_CommandName
);
194 len
= strlen(arguments
);
196 AROS_BSTR_setstrlen(cli
->cli_CommandName
, len
+ 1);
197 CopyMem((APTR
)arguments
, s
, len
);
201 AROS_BSTR_setstrlen(cli
->cli_CommandName
, 0);
203 cli
->cli_Interactive
= FALSE
;
204 cli
->cli_CurrentInput
= from
;