in reply to Caturing 7zip output with Perl

Unfortunately too much of your example is either commented out or are variables which we cannot tell how you have set. An SSCCE would be preferable. Here's one showing how it works:

#!/usr/bin/env perl use strict; use warnings; my $command = 'echo foo'; my $stdout = `$command`; print "STDOUT: $stdout"; $command = 'ls some-missing-file'; my $stderr = `$command 2>&1 >/dev/null`; print "STDERR: $stderr"; print "\nNow display stdout while command runs:\n"; $command = 'echo bar;sleep 3; echo baz'; open my $pipe, "($command) |"; while (<$pipe>) { print; } close $pipe

Caveat: only tested on Linux. Differences on Win32 are O/S related and not something I can help you with.

Replies are listed 'Best First'.
Re^2: Capturing 7zip output with Perl
by Anonymous Monk on Feb 23, 2016 at 09:57 UTC

    Sorry for the messy code, the commented out bits are things I've tried and couldn't get working.

    Hopefully this is easier to read?

    Example of command line

    7z.exe a -mx0 -tzip c:\temp\test.zip d:\* -x!$recycle.bin
    our $zip_cmd = '"c:\Program Files\7zip\7z.exe"'; our $sysvolume = '"-x!System Volume Information"'; my $exclude_list = ''; $exclude_list = " -x!*RECYCLE.BIN -x!*Thumbs.db -x!*desktop.ini"; my $command = $zip_cmd . ' a -r -mx0 -tzip' . $exclude_list . ' ' . $s +ysvolume . ' ' . $target_zip . ' '; my $ZIP = undef; open($ZIP,"$command |") or die "$package: Could not open pipe for $com +mand, Error: $!\n"; while (my $line = <$ZIP>) { print $line; #Record in the log file $trace and print STDOUT $line; # Report it on the screen if neede +d } close $ZIP;

    I'll try your examples