From 52eae2bca0476cbb69283d4bf3c74ef4841ab12b Mon Sep 17 00:00:00 2001 From: Jaroslav Pulchart Date: Sun, 22 Nov 2026 16:48:03 +0100 Subject: [PATCH] Run: run every '+' continuation line once The Shell joins '+' continuation lines into Run's argument line, and the background CLI reads them from its script input. Run gave the commands the same handle as Input(). RunCommand() injects each command's arguments into Input() and flushes it afterwards, so only the first line ran. With continuation lines the commands now get their own NIL: input. The command taken from the argument line already holds these lines, so the buffered input is appended only to a single line; otherwise they would run twice. runcommandredir checks that every continued line runs once. --- .../debug/test/dos/runcommandredir/README | 7 ++-- .../dos/runcommandredir/runcommandredir.c | 19 +++++++++++ workbench/c/shellcommands/Run.c | 33 +++++++++++++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/developer/debug/test/dos/runcommandredir/README b/developer/debug/test/dos/runcommandredir/README index ce78697a372..363a748c590 100644 --- a/developer/debug/test/dos/runcommandredir/README +++ b/developer/debug/test/dos/runcommandredir/README @@ -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. diff --git a/developer/debug/test/dos/runcommandredir/runcommandredir.c b/developer/debug/test/dos/runcommandredir/runcommandredir.c index 10a5cc7f8a1..349eab545f5 100644 --- a/developer/debug/test/dos/runcommandredir/runcommandredir.c +++ b/developer/debug/test/dos/runcommandredir/runcommandredir.c @@ -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); diff --git a/workbench/c/shellcommands/Run.c b/workbench/c/shellcommands/Run.c index d98b1395d49..b92880fcca4 100644 --- a/workbench/c/shellcommands/Run.c +++ b/workbench/c/shellcommands/Run.c @@ -49,6 +49,7 @@ HISTORY 41.4: Preserve quoting and escapes in the child command line. + 41.5: Run every '+' continuation line, once. ******************************************************************************/ @@ -73,7 +74,7 @@ #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") ) { @@ -81,12 +82,13 @@ AROS_SHAH(STRPTR, ,COMMAND,/F,NULL , "The program (resp. script) to run (argume 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) { @@ -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. */ @@ -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; @@ -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 }, @@ -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); @@ -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);