marscld has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, There is a CGI file, which will output the result for unzipped data in webpage. E.g test.zip contains test.tgz and test.txt. The output of CGI is a webpage, which will show test.tgz test.txt However,When running

system("unzip test.zip")

in CGI file, it shows "Archive: test.zip inflating: test.tgz inflating: test.txt" automatically in corresponding webpage,this information is useless and not supposed to be shown in webpage. Could you please advice on how to eliminate the useless unzip information ? Thanks.

Thank you all for the help, the problem solved! Yep, there is more than one way to do it, it is why Perl is a fantastic programming language :)

Replies are listed 'Best First'.
Re: Invoke system("unzip") in CGI file,unexpected output
by chrestomanci (Priest) on Mar 03, 2011 at 08:13 UTC

    You are seeing the verbose messages from the unzip process in your web page because unzip is sending them to stdout, which is inherited from the caller's stdout. Stdout for a CGI script is the web page being generated, so if a CGI script starts a child process that emits output to stdout, that output will end up in the generated web page.

    As wind and cdarke suggested, you should use a perl module to unzip the archive, or if you can't redirect the output from the unzip process to /dev/null. You could also capture the output with a piped open and either parse or discard it

    Also, where does this zip archive come from? If it is uploaded by an untrusted user then have you considered the possibility of a Zip bomb?

      Thank you for the advice. The perl module might be a good choice.
Re: Invoke system("unzip") in CGI file,unexpected output
by cdarke (Prior) on Mar 03, 2011 at 08:01 UTC
    system("unzip test.zip > /dev/null");
    or:
    my $outp = qx(unzip test.zip);
    then test $outp, if required.
Re: Invoke system("unzip") in CGI file,unexpected output
by wind (Priest) on Mar 03, 2011 at 07:02 UTC

    I suggest you simply use the cpan module Archive::Zip

    - Miller

Re: Invoke system("unzip") in CGI file,unexpected output
by CountZero (Bishop) on Mar 03, 2011 at 07:02 UTC
    this information is useless and not supposed to be shown in webpage
    Without you showing the CGI script, we can only guess what is the reason.

    My guess is that the warble does not flutter with the primzo and thereby causes the flubby to shigger, but it could be something else entirely.

    :)

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Invoke system("unzip") in CGI file,unexpected output
by DrHyde (Prior) on Mar 03, 2011 at 10:44 UTC
    You need to use system("unzip test.zip|grep -v test")