Results 1 to 10 of 10
Feb 6, 2009, 13:32 #1
- Join Date
- May 2006
- Lancaster University, UK
- 2 Post(s)
- 0 Thread(s)
Running an Executable with Proc_Open - Reading until end of stream?
I'm running an executable (written in Fortran) that requires multiple stages of input and outputs a few rows explaining the next input etc.
(I don't have the source code to this executable)
So, I open the process with Proc_Open. The IN (relative to the executable) buffer is in $Pipes, the OUT buffer is $Pipes and the error buffer is $Pipes.
My problem is reading the whole of the OUT buffer before writing to the IN buffer. IIRC the OUT buffer needs to be fully read before the IN buffer can be written to.
Now, to read the block out of a stream, one would assume that the typical:
So, until I can get a solution which allows me to read up until the end, I'm having to read it line by line using fgets(). If I use fgets just one too many times, the PHP application freezes (and I have to exterminate the 'httpd.exe' processes and restart WAMP).
So, obviously I made a function to loop over reading a single line based on the parameter passed. This means I have to know how many lines need to be read - a tedious task because of the different paths the application can follow.
So, is there an automated way to read the whole of a pipe stream output from an application resource created by Proc_Open()?
It seems the status of the process is constant whether at the end of the stream or not, and feof is returning false even at the end of the buffer.
I'm running PHP5.2.6.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona