[SOLVED]Returned Variables

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

[SOLVED]Returned Variables

Postby jaywebster » Wed Sep 25, 2013 12:37 pm

I have the following code I am having trouble with.

I am using phpseclib to run a python script on a remote computer which is working fine. The python script should either return 'yes' or 'no', which it does although I cannot make $result equal 'yes' or 'no'.

Code: Select all
      include('Net/SSH2.php');
      $ssh = new Net_SSH2('server');
      if (!$ssh->login('<username>', '<password>')) { exit('Login Failed'); }
      $result = $ssh->exec('python /home/<username>/main.py');
      echo $result;            # displays ' yes '
      if($result == 'yes')
      {
         echo 'RESULT IS YES';
      }
      else
      {
         echo 'RESULT IS NO';    # This is displayed
      }


I am not sure why this is the case? Its been a while since I have used PHP, so don't know if I am missing something?

Thanks for any help.

Jay
Last edited by jaywebster on Wed Sep 25, 2013 3:54 pm, edited 1 time in total.
jaywebster
Traveler
 
Posts: 2
Joined: Wed Sep 25, 2013 12:24 pm

Re: Returned Variables

Postby TerraFrost » Wed Sep 25, 2013 3:40 pm

If it's displaying ' yes ' (without the single quotes but with the spaces) you probably need to be doing $result == ' yes ' then. You could also do trim($result) too.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Returned Variables

Postby jaywebster » Wed Sep 25, 2013 3:53 pm

I ended up fixing it with:

Code: Select all
#if(preg_replace('/[^A-Za-z0-9\-]/', '', $result) == 'yes')


but your solution is prob faster :)

Thanks for the reply TerraFrost
jaywebster
Traveler
 
Posts: 2
Joined: Wed Sep 25, 2013 12:24 pm


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 2 guests

cron