Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java Exec Problem with Unzip

Reply
Thread Tools

Java Exec Problem with Unzip

 
 
O.B.
Guest
Posts: n/a
 
      01-27-2006
I'm having an odd problem in trying to get the "unzip" utility to
execute without locking up the Java process. In the code below, the
runtime.exec command successfully executes but the process.wairFor()
loop locks up about halfway through the zip file extraction process.

Help?

public static void installJboss(String installDir) {
//
// Only copy files if JBoss not installed. Check this
// by searching for jbossDir/bin/run.jar
//
String result = "";
if ( !(new File(installDir + "/bin/run.jar")).exists() ) {
//
// Extract files
//
File jbossDir = new File(installDir);
if ( !jbossDir.exists()) {
jbossDir.mkdirs();
}
String command =
"utilities/bin/unzip.exe utilities/archives/jboss-4.0.2.zip -d "
+ jbossDir.getAbsolutePath();
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec(command);
process.waitFor();
if (0 != process.exitValue()) {
result = "Failed to execute: " + command;
}
} catch (InterruptedException e) {
// Ignore
} catch (IOException e) {
result = "Failed to execute: " + command;
}
}
return result;
}
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      01-27-2006
O.B. <(E-Mail Removed)> wrote:
> I'm having an odd problem in trying to get the "unzip" utility to
> execute without locking up the Java process. In the code below, the
> runtime.exec command successfully executes but the process.wairFor()
> loop locks up about halfway through the zip file extraction process.


Chances are the zip process is blocking trying to write to standard
output. Try adding this after you run the process:

final InputStream in = process.getInputStream();
new Thread(new Runnable() {
public void run()
{
try
{
while (in.read() != -1);
}
catch (IOException e)
{
logTheError(e);
}
}
}).start();


--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      01-27-2006

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed).. .
> O.B. <(E-Mail Removed)> wrote:
>> I'm having an odd problem in trying to get the "unzip" utility to
>> execute without locking up the Java process. In the code below, the
>> runtime.exec command successfully executes but the process.wairFor()
>> loop locks up about halfway through the zip file extraction process.

>
> Chances are the zip process is blocking trying to write to standard
> output. Try adding this after you run the process:
>
> final InputStream in = process.getInputStream();
> new Thread(new Runnable() {
> public void run()
> {
> try
> {
> while (in.read() != -1);
> }
> catch (IOException e)
> {
> logTheError(e);
> }
> }
> }).start();


Chris is correct, for more details, see
http://java.sun.com/j2se/1.5.0/docs/...g/Process.html

<quote>
The created subprocess does not have its own terminal or console. All its
standard io (i.e. stdin, stdout, stderr) operations will be redirected to
the parent process through three streams (getOutputStream(),
getInputStream(), getErrorStream()). The parent process uses these streams
to feed input to and get output from the subprocess. Because some native
platforms only provide limited buffer size for standard input and output
streams, failure to promptly write the input stream or read the output
stream of the subprocess may cause the subprocess to block, and even
deadlock.
</quote>

- Oliver


 
Reply With Quote
 
O.B.
Guest
Posts: n/a
 
      01-27-2006
O.B. wrote:
> I'm having an odd problem in trying to get the "unzip" utility to
> execute without locking up the Java process. In the code below, the
> runtime.exec command successfully executes but the process.wairFor()
> loop locks up about halfway through the zip file extraction process.
>
> Help?
>
> public static void installJboss(String installDir) {
> //
> // Only copy files if JBoss not installed. Check this
> // by searching for jbossDir/bin/run.jar
> //
> String result = "";
> if ( !(new File(installDir + "/bin/run.jar")).exists() ) {
> //
> // Extract files
> //
> File jbossDir = new File(installDir);
> if ( !jbossDir.exists()) {
> jbossDir.mkdirs();
> }
> String command =
> "utilities/bin/unzip.exe utilities/archives/jboss-4.0.2.zip -d "
> + jbossDir.getAbsolutePath();
> Runtime runtime = Runtime.getRuntime();
> try {
> Process process = runtime.exec(command);
> process.waitFor();
> if (0 != process.exitValue()) {
> result = "Failed to execute: " + command;
> }
> } catch (InterruptedException e) {
> // Ignore
> } catch (IOException e) {
> result = "Failed to execute: " + command;
> }
> }
> return result;
> }


Figured it out. It was a problem with the stdout buffer getting filled.
When I run unzip in quiet mode, the program finishes without glitches.

Someone pointed out java.util.zip.ZipFile and from what I have gathered
so far, it is a better solution.

 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      01-27-2006

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed).. .
> O.B. <(E-Mail Removed)> wrote:
>> I'm having an odd problem in trying to get the "unzip" utility to
>> execute without locking up the Java process. In the code below, the
>> runtime.exec command successfully executes but the process.wairFor()
>> loop locks up about halfway through the zip file extraction process.

>
> Chances are the zip process is blocking trying to write to standard
> output. Try adding this after you run the process:
>
> final InputStream in = process.getInputStream();
> new Thread(new Runnable() {
> public void run()
> {
> try
> {
> while (in.read() != -1);
> }
> catch (IOException e)
> {
> logTheError(e);
> }
> }
> }).start();


Or it could be writing to standard error, so you really should do the same
with getErrorStream(), though that requires creating another thread to empty
that stream.


 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      01-27-2006
"O.B." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm having an odd problem in trying to get the "unzip" utility to
> execute without locking up the Java process. In the code below, the
> runtime.exec command successfully executes but the process.wairFor()
> loop locks up about halfway through the zip file extraction process.


Why aren't you using the java.util.zip package?

--
Tony Morris
http://tmorris.net/

Java Questions and Answers
http://jqa.tmorris.net/



 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      01-27-2006
"Roedy Green" <(E-Mail Removed) > wrote in
message news:(E-Mail Removed)...
> On Sat, 28 Jan 2006 09:14:27 +1000, "Tony Morris" <(E-Mail Removed)>
> wrote, quoted or indirectly quoted someone who said :
>
> >Why aren't you using the java.util.zip package?

>
> Java.util.zip has one big drawback. It only understands a few of the
> possible compression algorithms. It pretty well can only deal with
> zips created by itself. If the zip came from the outside world, you
> need to exec something like wzunzip or pkunzip.
> --
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.


WTF? Got any proof? I call bullshit. The alternative being that my eyes have
been deceiving me for years, and the API specification implementation that
I've been working on is nothing more than a result of my delusional state.
You might be referring to zip format extensions created by applications such
as Winzip?

--
Tony Morris
http://tmorris.net/

Java Questions and Answers
http://jqa.tmorris.net/



 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      01-28-2006

"Roedy Green" <(E-Mail Removed) > wrote in
message news:(E-Mail Removed)...
> On Sat, 28 Jan 2006 09:35:28 +1000, "Tony Morris" <(E-Mail Removed)>
> wrote, quoted or indirectly quoted someone who said :
>
> >WTF? Got any proof?

> go read the winzip and pkzip websites where they talk about
> proprietary super compressor algorithms.
> --
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.


And do what with that information? Will that somehow invalidate the
java.util.zip package not supporting the zip algorithm?
I think I can wipe my brow - I'm not delusional after all.

--
Tony Morris
http://tmorris.net/

Java Questions and Answers
http://jqa.tmorris.net/



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-28-2006
On Sat, 28 Jan 2006 09:14:27 +1000, "Tony Morris" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>Why aren't you using the java.util.zip package?


Java.util.zip has one big drawback. It only understands a few of the
possible compression algorithms. It pretty well can only deal with
zips created by itself. If the zip came from the outside world, you
need to exec something like wzunzip or pkunzip.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-28-2006
On Sat, 28 Jan 2006 09:35:28 +1000, "Tony Morris" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>WTF? Got any proof?

go read the winzip and pkzip websites where they talk about
proprietary super compressor algorithms.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python unzip: os.popen3("unzip ...") or import zipfile? Rocky Zhou Python 0 04-02-2007 04:53 AM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
Exec/System call with spaces in exec path problem ... Random Task Perl Misc 12 12-04-2005 10:03 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM
Backup Exec 9.1: The Backup Exec job engine system service is not responding Christian Falch Computer Support 1 06-23-2004 02:22 AM



Advertisments