Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide system() output

Tags:

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

like image 892
user806168 Avatar asked Jul 15 '11 14:07

user806168


1 Answers

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! 
like image 176
csl Avatar answered Sep 17 '22 15:09

csl