How do I get the output of Win32::Process command in Perl?

Posted by rockyurock on Stack Overflow See other posts from Stack Overflow or by rockyurock
Published on 2010-04-03T18:26:18Z Indexed on 2010/04/03 23:13 UTC
Read the original article Hit count: 297

Filed under:
|

I am using use Win32::Process for my application run as below. It runs fine, but I did not get any way to get the output to a .txt file.

I used NORMAL_PRIORITY_CLASS rather than CREATE_NEW_CONSOLE to get the output on the same terminal itself, but I don't know how to redirect it to a txt file.

/rocky

#!/usr/bin/perl

use strict;
use warnings;
use Win32::Process;

Win32::Process::Create(my $ProcessObj,
                       "iperf.exe",
                       "iperf.exe -u -s -p 5001",
                       0,
            NORMAL_PRIORITY_CLASS,
                       ".") || die ErrorReport();
my @command_output;

push @command_output,$ProcessObj;

open FILE, ">zz.txt" or die $!;
print FILE @command_output;
close FILE;

sleep 10;
$ProcessObj->Kill(0);

sub ErrorReport{
    print Win32::FormatMessage( Win32::GetLastError() );
}

© Stack Overflow or respective owner

Related posts about perl

Related posts about Windows