• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem executing an exe executable!

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic