ID: 50524 Updated by: [email protected] Reported By: carsten_sttgt at gmx dot de -Status: Open +Status: Assigned Bug Type: Program Execution Operating System: win32 only PHP Version: 5.3.1 -Assigned To: +Assigned To: pajoye New Comment:
Agreed, it should behave the same. Previous Comments: ------------------------------------------------------------------------ [2009-12-23 14:22:30] carsten_sttgt at gmx dot de > This is expected, No, a different behavior on Linux/BSD/OS X and Windows is not expected. (and also between proc_open and the other program execution functions) > as also noted in the manual on the proc_open() page for the $cwd parameter. Well, > or NULL if you want to use the default value > (the working dir of the current PHP process) If you really test the script yourself, you can see that getcwd() is returning the correct working dir of the current PHP process, but proc_open is using something else. > then on Windows atleast This have nothing to do with Windows. Only a wrong usage of CreateProcess from the PHP developers in this case (lpCurrentDirectory is not set to the value of getcwd). ------------------------------------------------------------------------ [2009-12-23 13:56:25] [email protected] This is expected, as also noted in the manual on the proc_open() page for the $cwd parameter. If NULL is supplied to $cwd, then on Windows atleast the directory where the PHP script interpreter is located is the cwd. ------------------------------------------------------------------------ [2009-12-18 19:33:35] carsten_sttgt at gmx dot de Description: ------------ Hello, each program execution function: - exec() - passthru() - shell_exec() - system() - backtick operator or popen() is using the current script (working) directory as working directory for the command which is executed. Only proc_open() is using a different directory: - for apache2handler it the Apache ServerRoot - for CGI it's the php-cgi.exe directory - for FastCGI (mod_fgcid) it's also the php-cgi.exe directory On *nix (mod_fcgid) the proc_open() working directory is as expected also the script (working) directory. Regards, Carsten Reproduce code: --------------- <?php header('Content-Type: text/plain'); echo "------getcwd()---------\n"; echo getcwd()."\n\n"; echo "\n\n-------popen()---------\n"; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $cmd = 'dir'; } else { $cmd = 'ls'; } $process = popen($cmd, 'r'); while (!feof($process)) { echo fread($process, 80); } pclose($process); echo "\n\n-------passthru()------\n"; passthru($cmd); echo "\n\n------proc_open()------\n"; $descriptorspec = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ); $process = proc_open($cmd, $descriptorspec, $pipes); while (!feof($pipes[1])) { echo fread($pipes[1], 80); } fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); ?> Expected result: ---------------- getcwd: C:\Apache2.2\htdocs 3 times a directory listing of: C:\Apache2.2\htdocs Actual result: -------------- getcwd: C:\Apache2.2\htdocs 2 times (popen, passthru) a directory listing of: C:\Apache2.2\htdocs 1 time (proc_open) a directory listing of: apache2handler: C:\Apache2.2 or CGI/FastCGI: C:\PHP ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50524&edit=1
