This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problem executing an exe executable! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem executing an exe executable!" Watch "Problem executing an exe executable!" New topic
Author

Problem executing an exe executable!

mohsen fakhari
Greenhorn

Joined: May 04, 2003
Posts: 25
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

Perhaps some needed DLL is not being found; are the appropriate library locations on your PATH?


[Jess in Action][AskingGoodQuestions]
mohsen fakhari
Greenhorn

Joined: May 04, 2003
Posts: 25
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

Joined: Mar 22, 2000
Posts: 12761
    
    5


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

Joined: May 04, 2003
Posts: 25
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

Joined: May 04, 2003
Posts: 25
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem executing an exe executable!
 
Similar Threads
Runtime rt = Runtime.getRuntime(ssh command); hangs
Running a .bat/ .cmd file from Java
Run .exe file and return boolean true after successful installation
Runtime.exec( ) is hanging....
who can my question about this code