gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:16:15 24 4
gpt4 key购买 nike

我想在 Perl 脚本中使用 Windows 内置 FTP 工具来测量链接的吞吐量。因此该脚本创建以下命令脚本:

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

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

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

如果我在 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.

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

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

我对 Perl 不是很熟悉。有人知道如何获得那条线吗?

最佳答案

使用 open在管道模式下:

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

或使用反引号:

my  @programoutput=`$command`

关于perl - 如何使用 Perl 获取 DOS 工具的命令行输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/568846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com