Re: [R] Capturing info from system calls in Windows

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Sat, 26 Jan 2008 09:58:13 -0500

On 26/01/2008 9:17 AM, Dennis Fisher wrote:
> Colleagues,
>
> I am preparing scripts that will be used by others on both Windows and
> Linux/OSX platforms. The scripts call an existing Fortran
> application. The user may have any of a a variety of Fortran
> compilers - my goal is to determine whether or not the test command
> returns "no input files" or "command not found" (i.e., so that I can
> confirm which Fortran they are using).
>
> In OS X and Linux, I can do the following:

>>> TEST <- system("g77 2>&1", intern=TRUE)
>>> TEST
>> [1] "g77: no input files"
>>
>>> TEST <- system("f77 2>&1", intern=TRUE)
>>> TEST
>> [1] "sh: f77: command not found"

> I can then use grep to determine which of the two strings was returned.
>
> In Windows:
>>> TEST <- system("g95 2>&1")
>> g95: 2>&1: Invalid argument
>>> TEST
>> [1] 0
>> attr(, "exec.status"):
>> [1] 0
>> attr(, "exit.status"):
>> [1] 0
>>> TEST <- system("g95")
>> g95: no input files
>>> TEST
>> [1] 0
>> attr(, "exec.status"):
>> [1] 0
>> attr(, "exit.status"):
>> [1] 0

>
> As you can see, Windows replies "no input files"; however, that info
> is not captured in TEST. I presume that this is because standard
> error is dealt with different in Windows compared to Unix-line
> platforms. Any thoughts on how to capture standard error in Windows?

See ?system. You want intern=TRUE there, too.

 > system("gcc")
gcc.exe: no input files
 > system("gcc", intern=TRUE)
[1] "gcc.exe: no input files"

Duncan Murdoch

>
> Dennis
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 26 Jan 2008 - 15:02:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jan 2008 - 15:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive