[R] Capturing output from external executables, in windows
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Jan 24 15:13:51 CET 2007
On 1/24/2007 8:22 AM, Darren Obbard wrote:
> Hi,
>
> Any help on the following would be much appreciated
>
> I wish to capture the output (currently going to console) from an
> external executable.
>
> The executable is successfully run using
>
> system("program -switch ")
>
> and the output printed to the DOS console.
>
> How do I capture this output? I have tried redirecting the output to a
> text file, and then reading this in
>
> system("program -switch > textfile.txt")
> data<-scan("textfile.txt")
>
> But this does not seem to work (the textfile.txt is not written).
The redirection character ">" is normally handled by the shell. The
system() function is low level, so it will pass it directly to your program.
>
It
> does however work if I invoke the console to be permanent
>
> system("cmd /K program -switch > textfile.txt")
> data<-scan("textfile.txt")
>
> Unfortunately, this leaves me with an open console window I have to
> close manually.
Use the /C option instead of /K; it executes and then terminates. Or
use the "intern" or "show.output.on.console" arg to system().
Duncan Murdoch
>
> Is there a way of doing this (under windows) using system( ) or some
> other command? It appears that pipe( ) may do it, but I cannot
> understand the documentation.
>
> An example of the appropriate syntax would be an enormous help.
>
> Thanks in advance,
>
> Darren
>
> Darren.Obbard at ed.ac.uk
>
More information about the R-help
mailing list