[R] Capturing info from system calls in Windows
Duncan Murdoch
murdoch at stats.uwo.ca
Sat Jan 26 15:58:13 CET 2008
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.
More information about the R-help
mailing list