繁体   English   中英

如何在Perl中通过SSH获取在远程机器上执行的命令的STDERR和STDOUT?

[英]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 发送到stdoutstderr@cmd

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM