Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem executing an exe executable!

 
mohsen fakhari
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I'm trying to run a exe file named butil.exe from within a java application.
This is my code:

Process p = run.exec("d:\\modec160\\p_21\\butil.exe");
BufferedReader err =new BufferedReader(new InputStreamReader(p.getErrorStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}

while ((line = err.readLine()) != null) {
System.out.println(line);
}

int exitValue = p.waitFor();
System.out.println("Process exit value: " + exitValue);

exitValue is always 2.
Like many other programms 'butil' when run without any arguments will give a usage discription,
but I don't have anything.
When I give its arguments,it should ,make a text file but I don't have it too.
If it is important butil belongs to Btrieve,an old record manager and I'm using JDK1.4 on winXP

Any thing you think may help,may really help.

Thank you.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Perhaps some needed DLL is not being found; are the appropriate library locations on your PATH?
 
mohsen fakhari
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mr.Friedman

Thank you for your response.
I changed the working directory to where all needed DLLs are:
Process p = run.exec("d:\\modec160\\p_21\\butil.exe" , null , new File("d:\\modec160\\p_21"));
...

But results are still nothing!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Sorry, that wont work - it wont try to read err until it finishes all of in so it will hang up if anything is being written to err and not consumed

You need to provide for reading both streams at all times so two new Threads are called for, one for each stream.

Bill
 
mohsen fakhari
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr.Brogden!
Thank you for your response.

It seems there's not any thing written there.
It doesn't hang up.
In fact the error message generated by butil.exe should be written in 'in' or 'err';
I commented 'in' part and tested 'err' part alone:

/*
while ((line = in.readLine()) != null) {
System.out.println(line);
}
*/

while ((line = err.readLine()) != null) {
System.out.println(line);
}

I've still proecess exit value: 2
and nothing else.
Then I commented the 'err' part and testetd 'in' part,
nothing yet.
 
mohsen fakhari
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

If it may help:
I created a bat file with instructions to run butil and then
tried to run this bat file from within my java code.
Surprisingly it works!
I've error messages I should and whith correct arguments I've correct resulted files.

I'm still eager to do it by pure java.

Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic