Connecting Tech Pros Worldwide Help | Site Map

Win32::Process - gunzip and output

Paolo
Guest
 
Posts: n/a
#1: Sep 26 '05
There is something I can't understand which is the following.
I have a system command which runs a commandline to unzip a file:

my $Out = system ( $rootPath."bin/bin/gunzip -dfc ".
$SourceFilePath." > ".$rootPath.$DestinationPath.".txt");

This works fine.
since I would like to make it parallel and run 4 processes at a time I
wrote this code:

use Win32::Process;
my $cmdLine = " -dfc ".$SourceFilePath." >
".$rootPath.$DestinationPath.".txt";
my $Out = Win32::Process::Create(my $ProcessObj,
$rootPath."bin/bin/gunzip.exe",
$cmdLine,
1,
NORMAL_PRIORITY_CLASS, # or even
".") || die ErrorReport();

(really not rocket science!)

what happens is that gunzip, instead of creating an output file, it
prints to the stdout!!
I don't understand what's being screwed...
Joe Smith
Guest
 
Posts: n/a
#2: Sep 26 '05

re: Win32::Process - gunzip and output


Paolo wrote:[color=blue]
> There is something I can't understand which is the following.
> I have a system command which runs a commandline to unzip a file:
>
> my $Out = system ( $rootPath."bin/bin/gunzip -dfc ".
> $SourceFilePath." > ".$rootPath.$DestinationPath.".txt");[/color]

You really ought to simplify that. Most . concatenations are unneeded.
The first one is OK, but can be obviated by using "${variable}txt".
my $gunzip = "${rootPath}bin/bin/gunzip"
my $cmd="$gunzip -dfc $SourceFilePath >$rootPath$DestinationPath.txt";
print "$cmd\n" if $verbose;
system($cmd) == 0 or warn "system() failed; error code $?";
[color=blue]
> use Win32::Process;
> my $cmdLine = " -dfc ".$SourceFilePath." >
> ".$rootPath.$DestinationPath.".txt";
> my $Out = Win32::Process::Create(my $ProcessObj,
> $rootPath."bin/bin/gunzip.exe",
> $cmdLine,
> 1,
> NORMAL_PRIORITY_CLASS, # or even
> ".") || die ErrorReport();
>
>
> what happens is that gunzip, instead of creating an output file, it
> prints to the stdout!!
> I don't understand what's being screwed...[/color]

You're assuming that either Win32::Process::Create interprets ">" the
same way that CMD.EXE does. It doesn't. Either invoke CMD.EXE or
do the equivalent by redirecting STDOUT yourself.
-Joe
Newbie
 
Join Date: Sep 2005
Posts: 19
#3: Oct 5 '05

re: Win32::Process - gunzip and output


For my own benifet, could you please explain why you are using Win32::Process and not threads? Thanks in advance! Oh, you might also find http://search.cpan.org/~nwclark/Perl...p-0.17/gzip.pm usefull
Closed Thread