Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions developer/debug/test/dos/runcommandredir/README
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ executing the child; the test fails on the missing completion file.

Coverage includes RunBack's exact NIL form, distinct outer and child input/output
files, case-insensitive Run with QUIET, a plain Run with child redirections,
quoted child paths, failed outer input, ordinary duplicate redirections, and
subsequent shell usability. Successful runs remove their temporary files;
failed asynchronous launches retain evidence rather than reuse their paths.
quoted child paths, '+' continuation lines, failed outer input, ordinary
duplicate redirections, and subsequent shell usability. Successful runs remove
their temporary files; failed asynchronous launches retain evidence rather than
reuse their paths.

Expected result: RUN COMMAND REDIR TEST: 0 failures.

Expand Down
19 changes: 19 additions & 0 deletions developer/debug/test/dos/runcommandredir/runcommandredir.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ int main(int argc, char **argv)
if (complete)
{
BPTR oldIn = Input(), oldOut = Output();

/* '+' continuation: every line runs once, in order, reading NIL:. */
snprintf(result, sizeof result, "%s/continued-1", directory);
snprintf(inner, sizeof inner, "%s/continued-2", directory);
snprintf(outer, sizeof outer, "%s/continued-once", directory);
snprintf(command, sizeof command,
"Run >NIL: \"%s\" %s +\n\"%s\" %s +\nEcho >>%s ONCE\n",
payload, result, payload, inner, outer);
check(SystemTags((CONST_STRPTR)command, SYS_Asynch, FALSE, TAG_DONE) == RETURN_OK,
"continued Run launch status");
check(waitFor((CONST_STRPTR)result, "EMPTY\n"), "first continued command reads NIL:");
check(waitFor((CONST_STRPTR)inner, "EMPTY\n"), "second continued command runs");
check(waitFor((CONST_STRPTR)outer, "ONCE\n"), "last continued command runs");
Delay(50);
check(matches((CONST_STRPTR)outer, "ONCE\n"), "continued commands run once");
check(DeleteFile((CONST_STRPTR)result), "remove first continued output");
check(DeleteFile((CONST_STRPTR)inner), "remove second continued output");
check(DeleteFile((CONST_STRPTR)outer), "remove last continued output");

snprintf(outer, sizeof outer, "%s/failed-outer", directory);
snprintf(inner, sizeof inner, "%s/should-not-exist", directory);
snprintf(result, sizeof result, "%s/should-not-run", directory);
Expand Down
33 changes: 30 additions & 3 deletions workbench/c/shellcommands/Run.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
HISTORY

41.4: Preserve quoting and escapes in the child command line.
41.5: Run every '+' continuation line, once.

******************************************************************************/

Expand All @@ -73,20 +74,21 @@

#include "run_handle.h"

AROS_SH2H(Run, 41.4, "Start a program as a background process\n",
AROS_SH2H(Run, 41.5, "Start a program as a background process\n",
AROS_SHAH(BOOL , ,QUIET ,/S,FALSE,"\tDon't print the background CLI's number"),
AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (arguments allowed)\n") )
{
AROS_SHCOMMAND_INIT

struct CommandLineInterface *cli = Cli();
struct Process *me = (struct Process *)FindTask(NULL);
BPTR cis = BNULL, cos = BNULL, ces = BNULL;
BPTR cis = BNULL, sis = BNULL, cos = BNULL, ces = BNULL;
struct FileHandle *fh;
LONG argsize;
CONST_STRPTR argbuff;
STRPTR command = (STRPTR)SHArg(COMMAND);
LONG cmdsize = 0;
STRPTR nl;

if (command)
{
Expand Down Expand Up @@ -142,6 +144,13 @@ AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (argume
fh = BADDR(Input());
argsize = (fh->fh_End > 0 && fh->fh_Pos > 0) ? (fh->fh_End - fh->fh_Pos) : 0;

/* The Shell joins the continuation lines into the argument line, which
* the command already holds then.
*/
nl = strchr(command, '\n');
if (nl && nl[1])
argsize = 0;

/* Good, there's some buffered input for us.
* Append it to the command.
*/
Expand All @@ -164,6 +173,21 @@ AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (argume
}
}

/* The background CLI reads the command lines from cis. Each command it
* runs gets its arguments injected into Input(), which is flushed after
* the command, so with '+' continuation lines a shared handle loses the
* lines not yet read. Give the commands their own input then.
*/
nl = strchr(command, '\n');
if (nl && nl[1])
{
sis = Open("NIL:", MODE_OLDFILE);
if (!sis)
goto error;
}
else
sis = cis;

cos = DuplicateRunHandle(Output(), DOSBase);
if (!cos)
goto error;
Expand Down Expand Up @@ -193,7 +217,7 @@ AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (argume
struct TagItem tags[] =
{
{ SYS_ScriptInput, (IPTR)cis },
{ SYS_Input, (IPTR)cis },
{ SYS_Input, (IPTR)sis },
{ SYS_Output, (IPTR)cos },
{ SYS_Error, (IPTR)ces },
{ SYS_CliType, (IPTR)CLI_RUN },
Expand All @@ -206,6 +230,8 @@ AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (argume
}
else
{
if (sis != cis)
Close(sis);
Close(cis);
Close(cos);
Close(ces);
Expand All @@ -220,6 +246,7 @@ AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (argume
{
LONG error = IoErr();
PrintFault(error, "Run");
if (sis && sis != cis) Close(sis);
if (cis) Close(cis);
if (cos) Close(cos);
if (ces) Close(ces);
Expand Down
Loading