• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling .exe file from java  RSS feed

 
Annie Tang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/EaseUp
 
Annie Tang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to start by reading this article. It explains all the things that can go wrong when using Runtime.exec.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!