[R] system vs shell wait command

Emmanuel Charpentier emm.charpentier at free.fr
Sun Jan 24 16:36:41 CET 2010


Le dimanche 24 janvier 2010 à 04:25 -0800, robbert blonk a écrit :
> Dear All,
> 
> I try to invoke a second program (called "gencont") within a R script.
> However this second program needs some time to finish. After finishing the
> output should be read into R and used for further calculation.
> 
> Under windows, it perfectly works:
> 
> result<-shell("gencont < yn.txt",intern=TRUE,wait=TRUE) 
> # R waits untill the program finishes (apporx 3 min) and uses the result as
> an object. "yn.txt" contains the answer to a question prompted by the second
> program before running
> resultf<-result[length(result)] 
> # reads the last line, which contains the required result
> 
> However, At our Linux server, shell() doesn't work. Here, I'll need
> system()...
> result<-system("./gencont.exe < yn.txt",intern=TRUE,wait=TRUE) #slightly
> different

You're using a Windows executable through wine (maybe "transparently"
via mod_binmisc) ? And this executable prints its output on the
console ? Right ?

> resultf<-result[length(result)] #same
> 
> The problem now is that R under Linux does not wait for the second program
> to finish, even if wait = TRUE...how come?

Might be wine, might be, more probably, gencont.exe : I have encountered
some windows programs whose main purpose was to set things up and launch
a second process which did "the real work". Cases in point : Office 2000
and Office 2003 installers [yuck !], for example.

FWIW, system("wineconsole cmd") opens a new window and waits for it's
user to type exit. It returns 0 as a result.

ISTR that Windows98' COMMAND.COM had an (internal ?) command called
"start" launching another process, with an option to wait or not for it
to terminate before returning ; this could be true of Windows 2000 and
later, but I can't check right now. Wine's own cmd.exe has a start
program :

wineconsole --backend=curses cmd

CMD version 1.1.31

Z:\home\charpent>start
Lance un programme, ou ouvre un document dans le programme normalement
utilisé avec cette extension.
Usage :
start [options] fichier_programme [...]
start [options] fichier_document

Optionss:
/M[inimized] Lance le programme minimisé.
/MAX[imized] Lance le programme maximisé.
/R[estored]  Lance le programme normalement (ni minimisé ni maximisé).
/W[ait]      Attend que le programme lancé se termine, et termine
ensuite avec son code de sortie.
/ProgIDOpen  Open a document using the following progID.
/L           Montre la licence d'utilisation.

start.exe version 0.2 Copyright (C) 2003, Dan Kegel
Start est fourni sans AUCUNE GARANTIE  ; pour les ddtails lancez avec
l'option /L
.
Ceci est un logiciel libre, et vous  êtes invité à le redistribuer
sous certaines condition; lancez 'start /L' pour les détails.
Z:\home\charpent>

This might help you ...

> What should I do?

I seriously doubt that system') can read back wht is spit in the
console. Better redirect that to another text file.

Some options come to mind, but beware : I didn't try any of them, not
having your "gencont.exe" program.
- system("wineconsole cmd gencont.exe < yn?txt > result.txt"), then
result<-read.lines("result.txt") ?
- ftp your input to a windows box, "ssh -f <yourwindowsbox> gencont.exe
< yn.txt > results.txt", ftp your results back (or, equivalently,
working on a Windows "share") ?
- port gencont.exe to linux ? :-) (this might seem silly, but might be
the easiest solution if this program is (as it seems according to your
partial explanations) a simple "filter" (read data, munch them, spit
output) not using windows-specific functions or system calls).

HTH,

					Emmanuel Charpentier



More information about the R-help mailing list