![](/img/trans.png)
[英]How to get STDERR in Perl from a command executed in pipe with su -c
[英]How can I get STDERR and STDOUT of a command executed on a remote machine through SSH in Perl?
我必须通过 Expect 模块执行的 SSH 连接到远程机器。 如果可能,我必须单独访问STDERR
/ STDOUT
并查看 output。我可以重定向脚本的 output,例如
$command = "ssh <script> 2>/tmp/stderr.output"
$exp = Expect->spawn($command) or die "Cannot spawn\n";;
my @command1= $exp->expect(5);
但后来我必须再次远程连接以检查stderr.output
。 有没有一种方法可以分别返回STDERR
/ STDOUT
。
您可能要考虑使用提供capture2
方法的Net::OpenSSH :
($output, $errput) = $ssh->capture2(\%opts, @cmd)
捕获由远程计算机上的@cmd 发送到
stdout
和stderr
的@cmd
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.