Page 1 of 1

php proc_open() HELP !! (windows )

Posted: Sat Sep 25, 2010 12:31 pm
by jkarr
Hi all ,
I have this problem about 4 days and can't find any solution .
I 'm trying to call a executable with proc_open() (i have tried system() , exec() and popen() but i had the same results ) , the problem is too weird because this executable is running perfect in command prompt but in php the executable return " EInOutError: I/O error 6 " , i have run my php script with other executables and it runs correctly , so i create a simple executable with Delphi and the only thing is doing is echoes "from cmd" and then i run it from cmd and was correctly executed so i run it from php i get :madblow: again " EInOutError: I/O error 6 "
so my question is :

why i can't execute any console executable from php compiled with Embarcadero Delphi 2010 ?
what is the difference from a real command prompt and the proc_open() ?

my system is a windows 7 prof x64 i run the latest xampp (apache runs as a service )
i tested in a windows xp 32 bit latest xampp (apache runs as service ) but i get same results


thanks for your time jkarr .

my php code

Code: Select all

class Process
{
    public static function open($command)
    {
        $retval = '';
        $error  = '';

        $descriptorspec = array(
            0 => array('pipe', 'r'),
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w')
        );

        $resource = proc_open($command, $descriptorspec, $pipes, null, $_ENV);
        if (is_resource($resource))
        {
            $stdin  = $pipes[0];
            $stdout = $pipes[1];
            $stderr = $pipes[2];

            while (! feof($stdout))
            {
                $retval .= fgets($stdout);
            }

            //while (! feof($stderr))
            //{
                $error = fgets($stderr);
			//}

            fclose($stdin);
            fclose($stdout);
            fclose($stderr);

            $exit_code = proc_close($resource);
        }

        if (! empty($error))
            throw new Exception($error);
        else
            return $retval;
    }
}
try
{
    $output = Process::open('cd ../htdocs/ccc/  & testDelphi.exe');
	echo $output;
	// do something with the output
}
catch (Exception $e)
{
    echo $e->getMessage() . "\n";
    // there was a problem executing the command
}

Re: php proc_open() HELP !! (windows )

Posted: Sat Sep 25, 2010 8:55 pm
by requinix
Check the proc_open manual page's comments for a lot of code samples. Try a few of them on your executable and see if you get the same results.

Also, I'm not sure about that command. & works on a shell but you aren't using a shell. Try a simple

Code: Select all

'../htdocs/ccc/testDelphi.exe'
Ah, in Windows it uses cmd.exe by default. Try the path to the file directly anyways, and if that doesn't work, giving bypass_shell=true in the "other_options" argument as well.

Re: php proc_open() HELP !! (windows )

Posted: Sun Sep 26, 2010 9:32 am
by jkarr
thanks for answering
i have used several examples with proc_open() and with others ( system() exec() ) same result ... i try that you purpose and get '..' ЫЬд ШдШЪдрихЭЬлШа рк ЬйрлЬиабу у ЬерлЬиабу Ьдлжву, i change the enctype to utf-8 but nothing ... i change the path to C:/xampp/htdocs/ccc/testDelphi.exe and i get again EInOutError: I/O error 6 any other executable works fine i can not understand what happens and i can even imagine why i get this error on every Delphi executable

Code: Select all

 $resource = proc_open($command, $descriptorspec, $pipes, null, $_ENV);
    //change to 
  $resource = proc_open($command, $descriptorspec, $pipes, null, $_ENV, array('bypass_shell'=>false) ); 


but get same results , any other idea ?

Re: php proc_open() HELP !! (windows )

Posted: Sun Sep 26, 2010 10:07 am
by requinix
...I meant to say bypass_shell=true :banghead:

What did you do to get that fake Russian? At least you're getting something, right?

Re: php proc_open() HELP !! (windows )

Posted: Sun Sep 26, 2010 10:16 am
by jkarr
tasairis wrote:...I meant to say bypass_shell=true :banghead:

What did you do to get that fake Russian? At least you're getting something, right?
ops sorry i forgot to mention that i was playing with the bypass_shell i change to false and true to see if i get something else but i get same results EInOutError: I/O error 6 .

i do not know what was this fake Russian message ... any idea ? ( thanks for quick answer )