Win32::Process - gunzip and output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paolo

    Win32::Process - gunzip and output

    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.$De stinationPath." .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 ".$SourceFilePa th." >
    ".$rootPath.$De stinationPath." .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

    #2
    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.$De stinationPath." .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$Dest inationPath.txt ";
    print "$cmd\n" if $verbose;
    system($cmd) == 0 or warn "system() failed; error code $?";
    [color=blue]
    > use Win32::Process;
    > my $cmdLine = " -dfc ".$SourceFilePa th." >
    > ".$rootPath.$De stinationPath." .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

    Comment

    • octoberdan
      New Member
      • Sep 2005
      • 18

      #3
      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
      Last edited by octoberdan; Oct 5 '05, 08:56 PM.

      Comment

      Working...