在perl / cgi文件中运行系统命令时缺少输出 [英] Missing output when running system command in perl/cgi file
问题描述
我需要编写一个CGI程序,它将显示一个系统命令的输出:
I need to write a CGI program and it will display the output of a system command:
echo "++++++"
VAR=$(expect -c " spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD match_max
100000 expect \"*?assword:*\" send -- \"$PASS\r\" send -- \"\r\" expect eof ")
echo $VAR
echo "++++++"
在CGI文件中:
my $command= "ksh ../cgi-bin/script.sh";
my @output= `$command`;
print @output;
最后,当我在unix中运行CGI文件时, $ VAR
是一个非常长的字符串,包括\\\
和一些分隔符。但是,当我在网络服务器上运行时,输出是
Finally, when I run the CGI file in unix, the $VAR
is a very long string including \n and some delimiters. However, when I run on web server, the output is
++++++
++++++
因此在传递Web界面/浏览器时,缺少 $ VAR
。
我知道也许问题是 $ VAR
是很长的字符串。
So $VAR
is missing when passing in the web interface/browser.
I know maybe the problem is $VAR
is very long string.
但是无论如何,除了将输出写入文件然后从浏览器中检索之外,还是要解决这个问题吗?
But anyway, is there anyway to solve this problem except writing the output to a file then retrieve it from browser?
感谢您对我的问题感兴趣。
Thanks if you are interested in my question.
推荐答案
script.sh
使用多个环境变量: $ USER
, $ HOST
, $ CMD
和
$ PASS
。 CGI环境将具有与登录Shell不同的环境变量集。在调用 script.sh
之前,您可能需要从CGI脚本中设置这些变量。
script.sh
uses several environment variables: $USER
, $HOST
, $CMD
and $PASS
. The CGI environment will have different environment variables set than a login shell. You may need to set these variables from your CGI script before calling script.sh
.
这篇关于在perl / cgi文件中运行系统命令时缺少输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!