2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
9 /******************************************************************************
25 Run a program, that is start a program as a background process.
26 That means it doesn't take over the parent shell.
30 QUIET -- avoids printing of the background CLI's number
32 COMMAND -- the program to run together with its arguments
38 To make it possible to close the current shell, redirect the output
41 Run >NIL: program arguments
53 ******************************************************************************/
55 #include <exec/memory.h>
56 #include <proto/exec.h>
57 #include <dos/dosextens.h>
58 #include <dos/dostags.h>
59 #include <dos/cliinit.h>
60 #include <dos/stdio.h>
61 #include <proto/dos.h>
62 #include <utility/tagitem.h>
63 #include <proto/alib.h>
66 #include <aros/debug.h>
68 #include <aros/shcommands.h>
70 AROS_SH2H(Run
, 41.3, "Start a program as a background process\n",
71 AROS_SHAH(BOOL
, ,QUIET
,/S
,FALSE
,"\tDon't print the background CLI's number"),
72 AROS_SHAH(STRPTR
, ,COMMAND
,/F
,NULL
, "The program (resp. script) to run (arguments allowed)\n") )
76 struct CommandLineInterface
*cli
= Cli();
77 struct Process
*me
= (struct Process
*)FindTask(NULL
);
78 BPTR cis
= BNULL
, cos
= BNULL
, ces
= BNULL
;
79 struct FileHandle
*fh
;
82 STRPTR command
= (STRPTR
)SHArg(COMMAND
);
88 cis
= Open("NIL:", MODE_OLDFILE
);
90 /* To support '+' style continuation, we're
91 * going to need to be a little tricky. We
92 * want to append *only* the buffered input
93 * left in Input() after the implicit ReadArgs
96 * First, let's see how much we have.
99 argsize
= (fh
->fh_End
> 0 && fh
->fh_Pos
> 0) ? (fh
->fh_End
- fh
->fh_Pos
) : 0;
101 /* Good, there's some buffered input for us.
102 * Append it to the command.
106 cmdsize
= strlen(command
);
108 argbuff
= BADDR(fh
->fh_Buf
) + fh
->fh_Pos
;
110 tmp
= AllocMem(cmdsize
+1+argsize
+1, MEMF_ANY
);
113 CopyMem(SHArg(COMMAND
), command
, cmdsize
);
114 command
[cmdsize
++]='\n';
115 CopyMem(argbuff
, &command
[cmdsize
], argsize
);
117 command
[cmdsize
++] = 0;
123 cos
= OpenFromLock(DupLockFromFH(Output()));
125 /* All the 'noise' goes to cli_StandardError
130 ces
= cli
->cli_StandardError
;
136 /* Use a duplicate of the CES lock
139 ces
= OpenFromLock(DupLockFromFH(ces
));
141 ces
= Open("NIL:", MODE_OLDFILE
);
143 if ( command
[0] != 0)
145 struct TagItem tags
[] =
147 { SYS_ScriptInput
, (IPTR
)cis
},
148 { SYS_Input
, (IPTR
)cis
},
149 { SYS_Output
, (IPTR
)cos
},
150 { SYS_Error
, (IPTR
)ces
},
151 { SYS_CliType
, (IPTR
)CLI_RUN
},
155 if ( SystemTagList((CONST_STRPTR
)command
,
158 PrintFault(IoErr(), "Run");
163 FreeMem(command
, cmdsize
);
170 FreeMem(command
, cmdsize
);