如何使用Perl获取DOS工具的命令行输出?

前端之家收集整理的这篇文章主要介绍了如何使用Perl获取DOS工具的命令行输出?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在Perl脚本中使用 Windows内置FTP工具来确保链接的吞吐量.因此,该脚本将创建以下命令脚本:

open <ip>
<username>
<password>
hash
get 500k.txt
quit@H_403_12@ 
 

然后我使用以下Perl代码运行命令脚本:

system(@args);
@args = ("ftp","-s:c:\\ftp_dl.txt");
system(@args);@H_403_12@ 
 

如果我在DOS框中运行命令,输出如下所示:

ftp> open <ip>
Connected to <ip>
220 "Welcome to the fast and fabulous DUFTP005 ftp-server :-) "
User (<ip>:(none)):
331 Please specify the password.

230 Login successful.
ftp> hash
Hash mark printing On  ftp: (2048 bytes/hash mark) .
ftp> get 500k.txt
200 PORT command successful. Consider using PASV.
150 opening BINARY mode data connection for 500k.txt (14336 bytes).
#######
226 File send OK.
ftp: 14336 bytes received in 0.00Seconds 14336000.00Kbytes/sec.
ftp> quit
221 Goodbye.@H_403_12@ 
 

为了能够获得吞吐量,我需要提取该行:

ftp: 14336 bytes received in 0.00Seconds 14336000.00Kbytes/sec.@H_403_12@ 
 

我对Perl不太熟悉.有人知道如何获得这条线吗?

解决方法

在管道模式下使用 open

open($filehandle,"$command|") or die "did not work: $! $?";
while(<$filehandle>)
{
#do something with $_
}@H_403_12@ 
 

或使用反引号:

my  @programoutput=`$command`@H_403_12@

猜你在找的Perl相关文章