Problems with exec()

P

phuonganh.Ng

Hi,
I'm writing a Java GUI for the text parsing program called "Apple Pie
Parser", the program was written in Unix C and have an executable file
(console) for windows. My program's being written in Windows, so I
tried to called the Runtime exec() method to get that .exe file to run
and pass my input into it. But it seems like i couldn't call it, cuz
nothing came up, and even when i tested, tried to call "cmd.exe",
nothing happened either. I'm wondering if there's anything to solve
this.

Thanks.
 
I

IchBin

Hi,
I'm writing a Java GUI for the text parsing program called "Apple Pie
Parser", the program was written in Unix C and have an executable file
(console) for windows. My program's being written in Windows, so I
tried to called the Runtime exec() method to get that .exe file to run
and pass my input into it. But it seems like i couldn't call it, cuz
nothing came up, and even when i tested, tried to call "cmd.exe",
nothing happened either. I'm wondering if there's anything to solve
this.

Thanks.
Not to put you off but maybe this article will help you out:

When Runtime.exec() won't
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
A

Andrew Thompson

* Call it what?
....
Not to put you off but maybe this article will help you out:

That article is very encouraging. I only glanced at each of
the five pages, but it indicated* that these type of problems
are easily debugged.

* It dumped stacktraces for every important action where
something could go wrong.
To the OP, have a look at how those code examples
give very *specific* details of what went wrong, down
to the line number. If looking at that article fails to
sort your immediate problem, I suggest you post a code
example that is self contained, and the first few lines
of the stacktraces it is causing when run.

Andrew T.
 
C

Chris Uppal

I'm writing a Java GUI for the text parsing program called "Apple Pie
Parser", the program was written in Unix C and have an executable file
(console) for windows. My program's being written in Windows, so I
tried to called the Runtime exec() method to get that .exe file to run
and pass my input into it. But it seems like i couldn't call it, cuz
nothing came up, and even when i tested, tried to call "cmd.exe",
nothing happened either. I'm wondering if there's anything to solve
this.

That program appears to read from its stdin and write to its stdout. If your
Java program is intended to make use of that (making use of the input and
output streams in the java.lang.Process instance corresponding to your exec()ed
program), then the most likely problem is that you have written to
the program's stdin but not flushed your output stream.

-- chris
 
P

phuonganh.Ng

Thanks for all your help, i'm still working on the problem. Below is my
code to simply open the application, input a sentence and wanting to
get the output.
----------------------------------------
try {
String out;
Process p =
Runtime.getRuntime().exec("C:/work/APP5.9/bin/app.exe");

BufferedReader output = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter input = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));

input.write("I tripped over a rock as I ran.\n");
input.flush();

while ((out = output.readLine()) != null) {
System.out.println(out);

}
output.close();
p.destroy();
}
catch (Exception err) {
err.printStackTrace();
}
 
P

phuonganh.Ng

Thanks for all your help, i'm still working on the problem. Below is my
code to simply open the application, input a sentence and wanting to
get the output.
----------------------------------------
try {
String out;
Process p = Runtime.getRuntime().exec("C:/work/APP5.9/bin/app.exe");

BufferedReader output = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter input = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));

input.write("I tripped over a rock as I ran.\n");
input.flush();

while ((out = output.readLine()) != null) {
System.out.println(out);

}
output.close();
p.destroy();
}
catch (Exception err) {
err.printStackTrace();
}
 
R

Robert Klemme

Thanks for all your help, i'm still working on the problem. Below is my
code to simply open the application, input a sentence and wanting to
get the output.
----------------------------------------
try {
String out;
Process p =
Runtime.getRuntime().exec("C:/work/APP5.9/bin/app.exe");

BufferedReader output = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter input = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));

input.write("I tripped over a rock as I ran.\n");
input.flush();

while ((out = output.readLine()) != null) {
System.out.println(out);

}
output.close();
p.destroy();
}
catch (Exception err) {
err.printStackTrace();
}

Depending on what the app does you might have to close the input before
you see anything.

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top