PHP SSH2 Exec - Getting PID -
how can pid process executed via ssh2.
what have tried :
ssh2_exec($ssh2, 'echo `ps aux | grep -f "' . $startcommand . '" | grep -v -f "grep" | awk \'{ print $2 }\'`');
and
ssh2_exec($ssh2, $startcommand.' > /dev/null 2>&1 & echo $!');
but result in echo resource id #2 or resource id #3 or resource id #4
you have use ssh2_fetch_stream function fetch ressource.
stdout_stream = ssh2_exec($ssh2, $command); $err_stream = ssh2_fetch_stream($stdout_stream, ssh2_stream_stderr); $dio_stream = ssh2_fetch_stream($stdout_stream, ssh2_stream_stddio); stream_set_blocking($err_stream, true); stream_set_blocking($dio_stream, true); $result_err = stream_get_contents($err_stream)); $result_dio = stream_get_contents($dio_stream));
Comments
Post a Comment