2 Copyright © 1995-2001, 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>
61 AROS_SH1(Execute
, 41.1,
62 AROS_SHA(STRPTR
, ,NAME
,/A
,NULL
))
67 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
)
89 BYTE tmpname
[2+3+10+10+2+2+1];
93 __sprintf(tmpname
, "T:Tmp%lu%lu%lu%lu",
94 ((struct Process
*)FindTask(NULL
))->pr_TaskNum
,
95 ds
.ds_Days
, ds
.ds_Minute
, ds
.ds_Tick
);
97 tmpfile
= Open(tmpname
, FMF_WRITE
|FMF_READ
|FMF_CREATE
|FMF_CLEAR
);
103 while((c
= FGetC(from
)) != -1 && FPutC(tmpfile
, c
) != -1);
111 "EXECUTE: error while creating temporary file\n");
122 while((c
= FGetC(cli
->cli_CurrentInput
)) != -1 && FPutC(tmpfile
, c
) != -1);
128 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
137 Close(cli
->cli_CurrentInput
);
138 if (AROS_BSTR_strlen(cli
->cli_CommandFile
))
139 DeleteFile(BADDR(cli
->cli_CommandFile
));
142 LONG len
= strlen(tmpname
);
143 CopyMem(tmpname
, BADDR(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
;