Extracting string from shell_exec call

From: Date: Wed, 28 Jul 2004 05:52:33 +0000
Subject: Extracting string from shell_exec call
Groups: php.general 
Request: Send a blank email to php-general+get-192073@lists.php.net to get a copy of this message
Hello all. I have a function that executes the unzip command. function test_unzip($command) {
       $stdout = shell_exec($command);
       echo $stdout;
} This is the content of $stdout after calling it with $command = "unzip ./email/test.zip"; Archive: ./email/test.zip inflating: ./txt/test.txt What I want to do is to extract the value(s) after inflating, so that I can check what was extracted from the zip. The reason why I cannot use the PHP zip functions is that I have to use a different decompressing utility other than unzip which outputs a different thing. Depending on what is output then I can decide what tool to use. So I need to extract test.txt from the string above. How can I do it? Sometimes the unzip utility is not compatible with the zip file because it might be proprietary. Therefore I will call pkzipc instead of unzip. Whenever I have the string from executing unzip : Archive: proprietary.zip
  skipping: proprietary.txt              `shrink' method not supported
Now, instead of inflating I have skiping because I cannot unzip this zip file with the free unzip utility, instead I call pkzipc and I then suceed: pkunzip proprietary.zip PKZIP(R) Version 6.0 FAST! Compression Utility for Linux X86 Copyright 1989-2002 PKWARE Inc. All Rights Reserved. Evaluation Version PKZIP Reg. U.S. Pat. and Tm. Off. Patent No. 5,051,745 Extracting files from .ZIP: pv0551.zip Unshrinking: proprietary.txt Therefore, what I need help with is to analyze the $stdout variable: If that contains inflating I need to know what was decompressed. If contains skipping then I must call this function using pkzipc instead. Then I must extract whatever value after Unshrinking: Can anyone help? Thanks in advance.

« previous php.general (#192073) next »