Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP proc_open on windows

Tags:

php

windows

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?

like image 801
Ed Heal Avatar asked Mar 28 '12 14:03

Ed Heal


2 Answers

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

like image 97
Alfred Godoy Avatar answered Oct 23 '22 07:10

Alfred Godoy


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)
    );
like image 27
Steve Lloyd Avatar answered Oct 23 '22 08:10

Steve Lloyd