Question about phpseclib and exec() ?

Hello,

I am trying to connect a unix server using ssh (phpseclib) and running an external program like 'C' program or a fortran program. I am using exec() to run .out. My code looks this way

Code:
echo $ssh->exec('./a.out');
a.out is a executable for program to add two numbers and the inputs are hardcoded within the 'C' program.

This piece of code works perfectly when the inputs are hardcoded in the 'C' program. But when I try to pass the arguments to exec(), the php script becomes unresponsive. After modification to accept inuts for .out, my code looks this way,

Code:
echo $ssh->exec("./a.out");
echo $ssh->exec("10 20");

where a.out is an executable for a simple program to add two numbers and 10 and 20 are inputs to a.out. I did modify the code as below and tried few options

Code:
$ssh->exec("./a.out '10' '20'");
$ssh->exec("./a.out ; '10 20'");

but none of them worked. All the above php scripts became unresponsive.
How do I pass inputs to a.out in next line using exec()?
Any inputs on this are greatly appreciated.

Thanks in Advance..
 
The only correct way is
Code:
$ssh->exec("./a.out 10 20");

If that doesn't work there's something wrong with the way a.out handles arguments.
 
Thanks SirDice for the reply. I could able to run the script using comamnd line arguments. My fortran code (for accepting inputs as command line arguments) is given below.

Code:
PROGRAM test_getarg
        CHARACTER *10 a,b,c
        real ip1,ip2,ip3
        CALL getarg(1,a)
        read (a,*) ip1
        CALL getarg(2,b)
        read (b,*) ip2
        CALL getarg(3,c)
        read (c,*) ip3
        sum = ip1+ip2+ip3
        write(*,*) sum
        END PROGRAM test_getarg

Unfortunately, this way of accepting inputs as command line arguments doesnt serve the purpose (As the fortran program needs to change/modify each time so as to accepts inputs in the command line format).
I could able to run the php script using

Code:
 $ssh->exec("./a.out 10 20 30");

My actual code looks this way

Code:
  PROGRAM world
        IMPLICIT NONE
        real a,b,c,sum
        read (*,*) a,b,c
        sum = a+b+c
        write(*,*) sum
        END

In the above code, compiler waits for inputs after hitting ./a.out. The output in this case looks as below,

Code:
] ./a.out
] 10 20 30
] 60.0

Iam trying to replicate the same using exec(). Iam using phpseclib ssh2 to connect ssh.
Thanks SirDice for your reply..
 
Yes SirDice, this is interactive.. Unfortunately, those functions are not supported with SSH2. Earlier I used PHPTelnet to do these interactive jobs. Every thing worked perfectly. I could run big fortran programs with large input data. But couple of weeks ago, my school web admin has blocked telnet and said telnet would be blocked in future. So need to rely on ssh.
 
Back
Top