Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Created August 18, 2012 13:41
Show Gist options
  • Save yuya-takeyama/3386926 to your computer and use it in GitHub Desktop.
Save yuya-takeyama/3386926 to your computer and use it in GitHub Desktop.
proc_open()'s $cwd argument
$ cat proc_open_cwd.php
<?php
$fdSpecs = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$process = proc_open('php -r "var_dump(getcwd());"', $fdSpecs, $pipes);
echo 'Without $cwd argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
echo PHP_EOL;
$process = proc_open('php -r "var_dump(getcwd());"', $fdSpecs, $pipes, NULL);
echo 'With NULL as $cwd argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
echo PHP_EOL;
$process = proc_open('php -r "var_dump(getcwd());"', $fdSpecs, $pipes, getcwd());
echo 'With getcwd() as $cwd argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
echo PHP_EOL;
$process = proc_open('php -r "var_dump(getcwd());"', $fdSpecs, $pipes, '/');
echo 'With "/" as $cwd argument:', PHP_EOL;
echo stream_get_contents($pipes[1]);
$ php proc_open_cwd.php
Without $cwd argument:
string(29) "/Users/yuya/dev/php/proc_open"
With NULL as $cwd argument:
string(29) "/Users/yuya/dev/php/proc_open"
With getcwd() as $cwd argument:
string(29) "/Users/yuya/dev/php/proc_open"
With "/" as $cwd argument:
string(1) "/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment