[英]Missing output when running system command in perl/cgi file
I need to write a CGI program and it will display the output of a system command: 我需要编写一个CGI程序,它将显示系统命令的输出:
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 "++++++"
In CGI file: 在CGI文件中:
my $command= "ksh ../cgi-bin/script.sh";
my @output= `$command`;
print @output;
Finally, when I run the CGI file in unix, the $VAR
is a very long string including \\n and some delimiters. 最后,当我在unix中运行CGI文件时,
$VAR
是一个很长的字符串,包括\\ n和一些定界符。 However, when I run on web server, the output is 但是,当我在Web服务器上运行时,输出为
++++++ ++++++
So $VAR
is missing when passing in the web interface/browser. 因此,在通过Web界面/浏览器时缺少
$VAR
。 I know maybe the problem is $VAR
is very long string. 我知道也许问题是
$VAR
是很长的字符串。
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
uses several environment variables: $USER
, $HOST
, $CMD
and $PASS
. script.sh
使用几个环境变量: $USER
, $HOST
, $CMD
和$PASS
。 The CGI environment will have different environment variables set than a login shell. 与登录外壳程序相比,CGI环境将设置不同的环境变量。 You may need to set these variables from your CGI script before calling
script.sh
. 在调用
script.sh
之前,您可能需要从CGI脚本设置这些变量。
Try finding where commands like expect and ssh that you are calling are on your system and adding their directory paths to the PATH used by your script. 尝试找到您正在调用的命令(例如Expect和ssh)在系统上的位置,并将其目录路径添加到脚本使用的PATH中。 Ie
即
which expect
returns /usr/bin/expect then add the line: 返回/ usr / bin / expect,然后添加以下行:
PATH=$PATH:/usr/bin && export PATH
near the beginning of the ksh script. 在ksh脚本的开头附近。 During debug you may also want to redirect stderr to a file by appending 2>/tmp/errors.txt to the end of your command since stderr is not shown in the browser.
在调试期间,您可能还想通过将2> /tmp/errors.txt附加到命令末尾来将stderr重定向到文件,因为浏览器中未显示stderr。
my $command= "ksh ../cgi-bin/script.sh 2>/tmp/errors.txt";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.