I need to fix this little mistake. First, let me talk about a small fact: In the Windows CLI, you cannot run a program with a space along its path unless you escape:
C:\>ab/c.bat 'a' is not recognized as an internal or external command, operable program or batch file. C:\>"ab/c.bat" C:\>
I use proc_open ... proc_close in PHP to start a process (program), for example:
function _pipeExec($cmd,$input=''){ $proc=proc_open($cmd,array(0=>array('pipe','r'), 1=>array('pipe','w'),2=>array('pipe','w')),$pipes); fwrite($pipes[0],$input); fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]); // max execusion time exceeded ssue fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]); fclose($pipes[2]); $rtn=proc_close($proc); return array( 'stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>(int)$rtn ); } // example 1 _pipeExec('C:\\ab\\c.bat -switch'); // example 2 _pipeExec('"C:\\ab\\c.bat" -switch'); // example 3 (sounds stupid but I had to try) _pipeExec('""C:\\ab\\c.bat"" -switch');
Example 1
- RESULT: 1
- STDERR: 'C: \ a' is not recognized as an internal or external command, operating program, or batch file.
- STDOUT:
Example 2
- RESULT: 1
- STDERR: 'C: \ a' is not recognized as an internal or external command, operating program, or batch file.
- STDOUT:
Example 3
- RESULT: 1
- STDERR: Incorrect file name, directory or volume name.
- STDOUT:
So, you see that in any case (double quotes or not) the code does not work. Is it me or am I missing something?
windows command-line-interface php path space
Christian
source share