Run external command in Java with syntax

Asked

Viewed 131 times

0

Hello, I’m using a DOS file to unzip files. zip, is UNZIP.EXE itself (DOS executable) I am mounting the code as follows:

Desktop.getDesktop().open(new File("e:\\unzip.exe teste.zip" ));

It does not work at all, it gives an error saying that ZIP file has not been found, I have tested it this way, and also it did not work:

ProcessBuilder p = new ProcessBuilder();
p.command("e:\\unzip.exe", "e:\\teste.zip");
p.start(); 

What am I doing wrong? Basically I need to run the unzip.exe command with the ZIP file name in sequence, that’s all.

I appreciate any help! Thank you!

1 answer

0

I took a look at the doc and you would have to pass a list of String with the parameters and not in this way that you did, experiment:

ProcessBuilder p = new ProcessBuilder(new String[]{"e:\\unzip.exe", "e:\\teste.zip"});
p.start();
  • did not work, he executed more simply does nothing and nor the error.

  • @user7605 if you give a getInputStream() he shows nothing?

  • how can I do it ? if you can pass me the command, I started in java a short time, I thank you!

  • After the p.start(); you can catch the inputStream with the p.getInputStream(), to read it can use that function here.

  • @user7605 take a look /\

  • I’m testing...

  • @Maiicon Carraro, he won’t let me use p.getInputStream();, only p.getclass();

  • really didn’t work out here!

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.