how to hide system() output

user806168 picture user806168 · Jul 15, 2011 · Viewed 23.5k times · Source

i am working on windows XP . i can successfully run a system() command through my browser by calling a TCL script that automates a ssh session. I also return a value from the script. however my problem is that the script dumps the entire ssh session in the browser.

my php script looks like :

$lastline=system('"C:\tcl\bin\tclsh.exe" \path to file\filename.tcl '.$username.' '.$pass,$val);  

filename.tcl:

spawn plink -ssh $user@$host   
expect "password:"  
send "$pass\r"  
expect "\prompt:/->"   
set $return_value [string compare /..string../ $expect_out(buffer)]   
/...some code...this runs fine/  
exit $return_value   

everything runs fine and i get $return_value back correctly but the php file prints the result of the execution of the entire ssh session in my browser which looks like:

Using username "admin". [email protected]'s password: === /*some text*/ === \prompt:/->.../some text/

i want to prevent the system() function from printing this in my browser
i have used the shell_exec() function but it returns the entire ssh session result (which i have parsed in the tcl script and got a precise value to return to the php script) is there a way i can do this without using shell_exec() but using system() instead

thanks in advance

Answer

csl picture csl · Jul 15, 2011

The documentation for system() specifically says:

Execute an external program and display the output

On that page are listed alternatives. If you use the exec function instead, it will only execute the commands without displaying any output.

Example:

<?php
echo "Hello, ";
system("ls -l");
echo "world!\n";
?>

will display the output of system:

$ php -q foo.php
Hello, total 1
-rw-r--r-- 1 bar domain users 59 Jul 15 16:10 foo.php
world!

while using exec will not display any output:

<?php
echo "Hello, ";
exec("ls -l");
echo "world!\n";
?>

$ php -q foo.php
Hello, world!