[Rd] system2 doesn't quote stdin on unix, unlike stdout, stderr & input and on Windows

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Tue Dec 17 17:38:27 CET 2019

Thank you for the report, I agree that system2() should quote stdin. It 
will be a change in behavior that is observable, but not documented (so 
users/programs should not depend on it) and in addition seems to be a 
bug. I'll still test on CRAN+BIOC packages, together with your patches 
for PR17673.


On 12/15/19 5:41 PM, Ivan Krylov wrote:
> Hi again!
> While investigating the bug report [*] I found out that on unix, system2
> does not quote its `stdin` argument while preparing the command line to launch.
> It does shQuote the `stdout` and `stderr` arguments, and also the `f <-
> tmpfile()` variable (which is used if `input` argument is provided),
> which seems to set a precedent. On Windows, stdin, stdout, and stderr are handled independently of the shell, so it also just works without the use of shQuote by the caller.
> Have people been relying on system2 not quoting the `stdin` argument, but
> quoting `stdout` and `stderr`? For what it's worth, neither R_runR in
> src/library/tools/R/check.R, nor .system_with_capture in
> src/library/tools/R/utils.R (the only callers of system2(..., stdin = ...)),
> nor their callers seem to be shQuote'ing the `stdin` argument.
> Nor the rare system2(..., stdin = ...) callers (or their callers) on CRAN
> seem to be quoting the `stdin` argument (I did find one exception [**]), it usually being "" or tmpfile() passed across a few function calls.
> Given the considerations above, would the following patch be a good idea?
> Index: src/library/base/R/unix/system.unix.R
> ===================================================================
> --- src/library/base/R/unix/system.unix.R	(revision 77566)
> +++ src/library/base/R/unix/system.unix.R	(working copy)
> @@ -102,7 +102,7 @@
>           writeLines(input, f)
>           ## here 'command' is a single command, unlike system()
>           command <- paste(command, "<", shQuote(f))
> -    } else if (nzchar(stdin)) command <- paste(command, "<", stdin)
> +    } else if (nzchar(stdin)) command <- paste(command, "<", shQuote(stdin))
>       if(!wait && !intern) command <- paste(command, "&")
>       .Internal(system(command, intern, timeout))
>   }

More information about the R-devel mailing list