Executing another application with PHP "exec" or "system" function.

27 views
Skip to first unread message

shimax

unread,
Jan 13, 2018, 10:15:51 AM1/13/18
to ZZEE PHPExe
Hello,

Within my application compiled by PhpExe, I would like to do:

<?php
$result = exec("e:/program/abc.exe parameter1 2>&1");

echo "finish$result";
?>
But it does not seem to work as I expected. I changed "exec" to "system" or "passthru", but in vain.

No output nor no return code in $result. And the program finishes very soon while it takes much longer when I execute the same command in DOS command window.
Even if I change the exe path to non-existing path deliberately, $result is empty. No error message at all!
The same program works when I execute it on Windows local server.

The program path is a full path like " e:/program/abc.exe", which does exist in my PC.

What am I missing?

Thank you in advance.

Waitman Gobble

unread,
Jan 13, 2018, 11:45:33 AM1/13/18
to php...@googlegroups.com
I don't think 2>&1 works on windows? maybe?

did you try using \\ instead of /
e:\\program\\abc.exe

also using backticks $t=`e:\\program\\abc.exe`

another way to grab the stdout/stdin, expecially if the process runs continuously.




$cmd = "e:\\program\\abc.exe -a yes -b no -c something";

$ds = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") );

flush();

$process = proc_open($cmd, $ds, $pipes, realpath('./'), array());

if (is_resource($process))
{
    while ($s = fgets($pipes[1]))
    {
        //do something with s
        flush();
    }
}




--
--
You received this message because you are subscribed to the Google
Groups "ZZEE PHPExe" group.
To post to this group, send email to php...@googlegroups.com
To unsubscribe from this group, send email to
phpexe+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phpexe?hl=en
---
You received this message because you are subscribed to the Google Groups "ZZEE PHPExe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpexe+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Waitman Gobble
Los Altos California USA
650-621-0423

shimax

unread,
Jan 14, 2018, 1:42:37 AM1/14/18
to ZZEE PHPExe
Thank you for your tips, Waitman.

2>&1 actually works. I was wrong on my test. Exec function successfully catches the output.
The error message was:
 "command" is not recognized as an internal or external command, operable program or batch file
or

file name, directory name or volume label syntax is incorrect


The message was Japanese in reality, but a short Google search shows the message was as the above in English.

What I have found out in the further tests, the problem lies in space characters in the parameter.

I had added " (double quote) in the beginning of the parameter and in its end. But this does not work well.
When I do not add "(double quote), as a matter of course, if the parameter includes space character, this does not work.

I thought the application (abc.exe) has a bug in dealing with a double quote within the parameter, but the same program works in Windows local server (Xampp).
On PHPexe, however, the same program does not work. So I wonder why.

Thank you in advance.

Ryotaro Shimazu

2018年1月14日日曜日 1時45分33秒 UTC+9 Waitman Gobble:

For more options, visit this group at
http://groups.google.com/group/phpexe?hl=en
---
You received this message because you are subscribed to the Google Groups "ZZEE PHPExe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpexe+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages