+ -
当前位置:首页 → 问答吧 → [初学请教] 想调用一个外部程序,然后将其输出重定向到一个指定文件中,怎么写?

[初学请教] 想调用一个外部程序,然后将其输出重定向到一个指定文件中,怎么写?

时间:2011-04-29

来源:互联网

不好意思,第一次写perl,如果太白了,还请大家见凉。
Baidu了许多,但是找不到能够用的。
  1. $path = "c:\\temp\\list.txt";
  2. my $hfile = open(source, "< $path");
  3. if ($hfile)
  4. {
  5.   print $path;
  6.   print "\n";

  7.   $input = IO::File->new($path);
  8.   my $outfile = "C:\\temp\\outfile.txt";
  9.   open IN, ">$outfile";

  10.   while(defined($line = $input->getline()))
  11.   {
  12.       chomp($line);
  13.       STDOUT->print($line);
  14.       system("ping $line"); #I want to redirect the output to a file.
  15.       print "\n";
  16.   }

  17.   $input->close();
  18.   $outfile->close();
  19. }

  20. close source;
复制代码

作者: 百分百好牛   发布时间: 2011-04-29

直接用管道啊....

system("ping $line > ping.file");

作者: yang200218   发布时间: 2011-04-29

热门下载

更多