[R] command prompt shell suppressing stdout?

From: Michael Neely <mneely_at_usc.edu>
Date: Tue, 22 Mar 2011 11:26:30 -0700


After four years of using R, I finally have run into a problem to which I can't find a solution in the guides or forums and thus I am making my first post.

Our lab has Fortran code for population modeling. I have been using R as a wrapper to process the raw data, generate a batch script that compiles the Fortran code, executes the code in a shell, and then extracts the output of the program for further analysis and plotting in R.

Because the Fortran modeling program can sometimes take hours or days to complete, depending on the complexity of the data and model, I want it to run outside of R to avoid tying it up. In Mac/Unix, I have been able to accomplish with a function that creates the batch script and then executes it with this command:

        system(paste("open -a Terminal.app ",shQuote(paste(getwd(),"/npscript",sep="")),sep=""))

This opens an independent instance of Terminal and executes the batch script. The user can provide input to the Fortran executables created/called by the batch script as required, and see the output in real time as the progress of the modeling is continually updated.

In Windows, I have been unable to accomplish this. I can generate the batch script code of course, and it runs perfectly in a command prompt window if I manually double-click it to execute. However, if I try to execute it from R, I appear to have no stdin capability (i.e. no user input possible) to the compiled Fortran executable and no stdout from the executable, i.e. no way to tell if the Fortran code is hung up, or simply churning away without updating the command prompt window. It does complete successfully with the expected output files, but for a long run, it is imperative to view progress normally reported by the executable.

Here are the first few lines of the batch script that I generate in R, simplified and with added line numbers for clarity:

  1. C:\bin\prep.exe DOS < control #run the prep program with command line arg to specify OS and input from control (also generated in R with user options to the function) to automate; no output visible in command prompt window; if control not specified, then executable waits for user keyboard input, resulting in a frozen blank window
  2. gfortran -o C:\bin\run.exe file1 file2 file 3 prepout... #compile "engine" files to run model with output of prep program; output visible in command prompt window
  3. C:\bin\run.exe #execute engine to run the model; no output visible

I have tried the following without success:

system("npscript.bat", wait=F, invisible=F) and all permutations system2("npscript.bat", wait=F, invisible=F) and all permutations shell("npscript.bat")
shell("start npscript.bat")

Is there any way to replicate the Unix behavior in Windows and launch a shell that runs the batch script with the same I/O capability as if I had manually launched it? Yes, I could have users manually launch the batch script, but it would be tidier if R could successfully complete the process.

Thanks very much.



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 Tue 22 Mar 2011 - 20:00:39 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 Tue 22 Mar 2011 - 20:10:24 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