如何隐藏 system() 输出 [英] how to hide system() output

查看:56
本文介绍了如何隐藏 system() 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Windows XP.通过调用自动执行 ssh 会话的 TCL 脚本,我可以通过浏览器成功运行 system() 命令.我还从脚本中返回一个值.但是我的问题是脚本在浏览器中转储了整个 ssh 会话.

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.

我的 php 脚本如下:

my php script looks like :

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

文件名.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   

一切正常,我正确地返回了 $return_value 但 php 文件在我的浏览器中打印了整个 ssh 会话的执行结果,如下所示:

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:

使用用户名admin".admin@10.135.25.150 的密码: ===/*some text*/=== \prompt:/->.../some text/

Using username "admin". admin@10.135.25.150's password: === /*some text*/ === \prompt:/->.../some text/

我想阻止 system() 函数在我的浏览器中打印这个
我使用了 shell_exec() 函数,但它返回了整个 ssh 会话结果(我在 tcl 脚本中解析了它并得到了一个精确的值来返回到 php 脚本)有没有办法不使用 shell_exec() 而是使用 system() 来做到这一点

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

提前致谢

推荐答案

system() 文档 特别说明:

执行外部程序并显示输出

Execute an external program and display the output

在该页面上列出了替代方案.如果您使用 exec 函数,它只会执行命令而不显示任何输出.

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

示例:

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

将显示system的输出:

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

使用 exec 时不会显示任何输出:

while using exec will not display any output:

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

$ php -q foo.php
Hello, world!

这篇关于如何隐藏 system() 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆