Search code examples
java7zippsexec

Launching a command line application that launches another command line application never responds


When I run the following command from command line, I can run 7-zip as a remote user and extract a file to a network share:

C:\PsExec.exe -u username -p password "C:\7z.exe" x -y -o\\network\extractedfiles\ C:\compressed.zip toextract.txt

I am running this generated line exactly as my application is running it (note I've altered the directories, paths, username, and passwords so that I can post it online). In fact, the line was copied from my application's logs.

But for some reason, when I run this command from Java using the following code, it sits and waits forever. No file appears on the "\network\extractedfiles\" path.

final Process copyFile = Runtime.getRuntime().exec( cmd );
final int exit = copyFile.waitFor();

Where cmd is the above string. Any ideas?

More Info 1:

I also meant to say that I noticed when this is run by command line, psexec launches z-zip in a separate command window. Could the problem be that the output from zip is not being disposed of? I tried closing the input stream but it did not seem to fix the problem I'm facing.

More Info 2:

I tried logging out output from the command, and here is what I got:

INFO 2012-05-03 15:07:55,188 - Command output: PsExec v1.98 - Execute processes remotely
INFO 2012-05-03 15:07:55,188 - Command output: Copyright (C) 2001-2010 Mark Russinovich
INFO 2012-05-03 15:07:55,188 - Command output: Sysinternals - www.sysinternals.com
INFO 2012-05-03 15:07:55,188 - Command output: 

Then it sits forever. When run on the command line the next line of output was:

C:\7z.exe exited with error code 0.

So it seems 7-zip is hanging. It does not even begin to extract the file though - when I check the directory where the file is expected to extract to nothing appears.

More Info 3:

I created my own unzipper in .net using the ionic.zip.dll. My unzipper was really simple - accepted params through command line, did not have any output. But it still did the exact same thing - unzipping does not start and the execution hangs. Maybe psexec is doing something weird??? Does the fact that psexec wants to run the unzipper in an external command console cause any problems for Java?


Solution

  • Probably there was an error you should read the streams from your process to know for sure