File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Calling .exe file from java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Calling .exe file from java " Watch "Calling .exe file from java " New topic
Author

Calling .exe file from java

Annie Tang
Greenhorn

Joined: Jul 24, 2009
Posts: 2
I'm trying to write this java program that calls a .exe file and read in the result.
The .exe file is written in c and has something like printf("hello") at the end.
I tried to do this:
try {
Process p = Runtime.getRuntime().exec("c:\\test\\a.exe");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println(br.readLine());
br.close();
}
catch (Exception err) {
err.printStackTrace();
}
but it keeps giving me null as a result.
Obviously I'm doing something worng, but I can't figure out what is it.
I would really appreciate if someone can help me with it.

Thanks a lot.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

http://faq.javaranch.com/java/EaseUp


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Annie Tang
Greenhorn

Joined: Jul 24, 2009
Posts: 2
I'm sorry. I've been stuck on this problem for several days and I'm getting pretty desperate. I apologize if I make people feel uncomfortable.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
You might want to start by reading this article. It explains all the things that can go wrong when using Runtime.exec.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Calling .exe file from java
 
Similar Threads
How to get the File Property Informations?
check values in a csv file in all files in a directory
Problems with installing Tomcat
Facing problem with running external exe from my java code
how to create .exe in java