severndigital Posted October 23, 2009 Share Posted October 23, 2009 here's what i got. $conn = ssh2_connect($this->_host); ssh2_auth_password($conn,$this->_user,$this->_pass)or die("Cannot Connect"); //build command line to include this jobnumber $command = '/usr/local/bin/invoiced_date.sh ' . $jobnumber; //issue the command line $stream = ssh2_exec($conn,$command); stream_set_blocking($stream,true); $output = ssh2_fetch_stream($stream,SSH2_STREAM_STDERR); echo 'what i got: ' . $output; when this echo's i get. what i got: Resource id #7 how do i turn Resource id #7 into actual information? Thanks in advance, C Quote Link to comment https://forums.phpfreaks.com/topic/178769-returning-data-from-an-ssh2_exec/ Share on other sites More sharing options...
salathe Posted October 23, 2009 Share Posted October 23, 2009 You can call stream_get_contents on the stream resource, $output. Quote Link to comment https://forums.phpfreaks.com/topic/178769-returning-data-from-an-ssh2_exec/#findComment-943005 Share on other sites More sharing options...
severndigital Posted October 23, 2009 Author Share Posted October 23, 2009 i tried that also with no luck.. just returns an empty variable. when I run the .sh script in the command line on the server it returns a line of text to terminal. that line of text should be outputting correct?? $conn = ssh2_connect($this->_host); ssh2_auth_password($conn,$this->_user,$this->_pass)or die("Cannot Connect"); //build command line to include this jobnumber $command = '/usr/local/bin/invoiced_date.sh ' . $jobnumber; //issue the command line $stream = ssh2_exec($conn,$command); stream_set_blocking($stream,true); $output = ssh2_fetch_stream($stream,SSH2_STREAM_STDERR); $output = stream_get_contents($output); echo 'what i got: ' . $output; is that code right .. or am I missing something?? Thanks again, C Quote Link to comment https://forums.phpfreaks.com/topic/178769-returning-data-from-an-ssh2_exec/#findComment-943014 Share on other sites More sharing options...
salathe Posted October 23, 2009 Share Posted October 23, 2009 You're reading STDERR (usually for errors), do you instead want to be reading STDIO (SSH2_STREAM_STDIO)? Quote Link to comment https://forums.phpfreaks.com/topic/178769-returning-data-from-an-ssh2_exec/#findComment-943079 Share on other sites More sharing options...
severndigital Posted October 23, 2009 Author Share Posted October 23, 2009 still no dice... i took this code directly from the php.net page for ssh2_fetch_stream $conn = ssh2_connect($this->_host); ssh2_auth_password($conn,$this->_user,$this->_pass)or die("Cannot Connect"); //build command line to include this jobnumber //$command = '/usr/local/bin/invoiced_date.sh ' . $jobnumber; $stdout_stream = ssh2_exec($conn, "ls"); $err_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR); $dio_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDIO); 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); echo 'Error gets: ' . $result_err; echo '<br/>'; echo 'Dio gets: ' . $result_dio; i removed my .sh script from the mix and am I just running an ls, and it comes still comes back blank. another thing that interesting is that the .sh script is actually running (it does what it is supposed to on the server i am ssh'ing to) I just can't get the variable to fill with output, which is what i need) Quote Link to comment https://forums.phpfreaks.com/topic/178769-returning-data-from-an-ssh2_exec/#findComment-943120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.