16

I have created a process using proc-open but under windows the stream-select does not work. What I am trying to achieve is to read from both stdout and stderr, whilst in addition writing to stdin and ensure that the output can be matched up with the inputs. Is there a workaround for windows to overcome this deficiency?

7
  • 2
    I think the only thing you can do is to set your pipes in non-blocking mode and check them manually, unfortunately. Commented Mar 28, 2012 at 14:17
  • 1
    @netcoder - I have tried this. stream_set_blocking returns false :-( Commented Mar 28, 2012 at 14:21
  • stderr and stdout cannot be set to non blocking. What are you trying to achieve exactly? Have some code? select may not be necessary here. Commented Apr 1, 2012 at 15:49
  • Can you distinguish messages printed to stderr from messages printed to stdout (by using some sort of regexp for example)? Commented Apr 6, 2012 at 16:12
  • @galymzhan - The two streams are diffenent in the fact that they come from two different file descriptors. Also, sometimes there is nothing to be read. Commented Apr 6, 2012 at 17:06

2 Answers 2

1

adding bypass_shell worked for me

$proc=proc_open($cmd,
        array(
            0=>array('pipe', 'r'), //stdin
            1=>array('pipe', 'w'), //stdout
            2=>array('pipe', 'w')  //stderr
            ),
        $pipes,
        $dir,
        null,
        array('bypass_shell'=>true)
    );
Sign up to request clarification or add additional context in comments.

Comments

0
+50

You are not very detailed on what is not working for you with stream-select on Windows. However, this is a working example on how to use stream-select. I just ran this successfully with PHP 5.4 on Windows XP.

Edit: Uhhmmm.. Seems like it was non-working after all... Sry, testing some more here.. :)

Edit again:

So, I did some more experimenting on this, but unsuccessfully.

Maybe you should just let the processes speak TCP/UDP/IP to each other?

Another way forward (if you still want to use stdout/stdin/stderr in your process) might be to use proc_open with file handlers, so your process is writing to files, and then use something similar to unix' inotify, loading this stuff with the PHP DOTNET class: Is there anything like inotify on Windows? to detect changes to the files...? Just an idea...

Or maybe change to a unix-like os? ;) Ok, that's it for me tonight. Good night

6 Comments

stream_select in your example seems useless. It just reads from stdout and stderr pipes without actually looking into what is returned in $read_streams. This could block if child process is busy (or child wrote into stderr when you're waiting data on stdout)
@AlfredGodoy - The problem is that windows select does not work. But unix/linux it seems to work. Sorry for the effort for code that does not work.
@AlfredGodoy - You get the bounty for the effort. Should not go to waste.
Thnx :) Added some more ideas on this in the answer.
@AlfredGodoy - I will put you on my list of kind people.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.