Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Perl中通过ssh从cat获取输入_Perl_Input_Ssh_Pipe - Fatal编程技术网

如何在Perl中通过ssh从cat获取输入

如何在Perl中通过ssh从cat获取输入,perl,input,ssh,pipe,Perl,Input,Ssh,Pipe,我正在尝试通过ssh对远程文件进行cat,并在本地脚本中逐行处理它。到目前为止我已经试过了 open(INPUT,"| ssh user@host cat /dir1/dir2/file.dat") 但很明显,它只是将文件.dat打印到标准输出 我知道我可能只需要scp文件并处理它,但是…您正在通过管道传输到ssh。我认为您需要将管道移动到另一端,以便可以读取cat命令的输出。我将使用 $file_contents = `ssh user@host cat /dir1/dir2/file.da

我正在尝试通过ssh对远程文件进行cat,并在本地脚本中逐行处理它。到目前为止我已经试过了

open(INPUT,"| ssh user@host cat /dir1/dir2/file.dat")
但很明显,它只是将文件.dat打印到标准输出

我知道我可能只需要scp文件并处理它,但是…

您正在通过管道传输到ssh。我认为您需要将管道移动到另一端,以便可以读取cat命令的输出。

我将使用

$file_contents = `ssh user@host cat /dir1/dir2/file.dat`;
@lines = split(/\n/, $file_contents);
.
.
. # process the file contents

它捕获了命令的输出(即文件的内容)。

是啊,我自己通过试错法找到了它:-D,但无论如何比你要多,为什么不直接说
@lines=qx/ssh…/
(在这里使用qx而不是倒勾来避免SO的标记)?这将同时运行和拆分(尽管它将保留\n的)。这就是说,这是效率较低的。如果文件非常大,您必须将整个文件加载到内存中以处理它。如果连接速度非常慢,则必须等待整个加载过程,然后才能处理其中的任何一个。OP的解决方案在修复后不会出现上述问题。根据我的经验,背勾通常是要避免的。