Bug 15508 - system() input parameter could be handled better?
Summary: system() input parameter could be handled better?
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.0.1
Hardware: All unix-other
: P5 normal
Assignee: R-core
Depends on:
Reported: 2013-10-25 00:02 UTC by David Rosenberg
Modified: 2015-12-14 13:47 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description David Rosenberg 2013-10-25 00:02:35 UTC
When system() has the parameter input, a tmp file f is written, and the final command line is given by:

     command <- paste(command, "<", f).

I think this would work more as expected if it were

     command <- paste("<", f,command)


The issue is that if command is a pipeline, such as "cat | wc", then the final command from system() gives the input to wc, rather than cat, which is probably not the expected behavior. In particular, the following command hangs, because cat is waiting for stdin:
system("cat | wc",input=c("a","b")) 

If we group the commands, like
system("(cat | wc)",input=c("a","b")) 
it works... but I can't think of any reason not to just be the stdin redirection first, so things work as expected in the natural way.
Comment 1 Brian Ripley 2014-05-14 13:31:14 UTC
The designers here took a minimal view of the shell (if any) invoked by the C-level 'system' command.  POSIX requires a shell that allows redirections in the 'shell execution environment' as well as of commands (Utilities volume ยง2.7), but a POSIX shell is not required (whereas all C-based commands support redirection, so redirecting commands is known to work).

It is likely that POSIX-compliant shells are now universal on Unix-alike R platforms (there are many fewer than there used to be), so we will test this.
Comment 2 Brian Ripley 2014-05-19 09:06:03 UTC
Seems to have passed testing on the platforms available to me.