lintunen has asked for the wisdom of the Perl Monks concerning the following question:

I have migrated a Perl script running under Linux/Apache that runs (which has no issues) to Windows Server 2008/IIS7. The program calls an external process by the following means:

open($R, "|C:/Progra~1/R/R-2.11.0-x64/bin/R CMD BATCH " . $R_FILE) or die $!;

What appears to be happening is that the following lines of code are being executed before the R script finishes executing. I have read some articles on various ways to make code wait but I haven't found a working solution. Not an experienced Perl programmer, I am hoping for some recommendations. I have analysed the http traffic and it appears that there is some kind of timing problem and there are no errors in the server logs.

Replies are listed 'Best First'.
Re: Execution of external process does not wait in IIS7/Windows
by cdarke (Prior) on Aug 19, 2010 at 11:58 UTC
    You are running in a pipe, it is not supposed to wait for the process to finish. The program runs in background, waiting for you to write something to the file handle $R. Use system if you want to wait for it to complete.

    Or maybe I mis-read your question?
Re: Execution of external process does not wait in IIS7/Windows
by dasgar (Priest) on Aug 19, 2010 at 22:25 UTC

    Are you needing read back the output of the external process? If not, the I would use system as cdarke has suggested.

    However, if you do need to read back the output, then you might consider using back ticks. Just beware that using back ticks can create problems if you're not careful. (For more details about using back ticks and some of the potential problems, check out one of my posts at Re: open with pipe) and afoken's reply. I gave a Linux example there, but the general idea will still apply to Windows.)

      Success! I changed the open statement with the pipe to backticks and the code waited. (I had no luck with system.) Thanks!