By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

exec() problem...need interaction with program being exec()'ed

P: n/a
I need my java program to exec an external .exe file, but the problem
is that this program being exec()'ed prompts the user for two pieces
of information. I am trying to get my java program to automatically
send data to the other program but for some reason the child hangs.
The first piece of info prompted for is an integer, and the second
prompt asks for a floating number. I am trying to send the program
"3\n" to satisfy the first prompt and ".9982\n" to satisfy the second
prompt. I am using this on windows XP with jsdk 1.4. The whole code
is:

import java.io.*;

class test {

public static void main(String[] args) throws Exception {
String numImages;
String density;
numImages = "3\n";
density = "0.9982\n";

System.out.println("creating child");

try {

Process p = Runtime.getRuntime().exec("apend.exe");

OutputStream out = p.getOutputStream();

out.write(numImages.getBytes());
out.write(density.getBytes());

p.getOutputStream().close();
p.waitFor();

System.out.println("child finished");

} catch (IOException e) {
}

}
}
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ch*************@yahoo.com (Chad) wrote in message news:<bc**************************@posting.google. com>...
I need my java program to exec an external .exe file, but the problem
is that this program being exec()'ed prompts the user for two pieces
of information. I am trying to get my java program to automatically
send data to the other program but for some reason the child hangs.
The first piece of info prompted for is an integer, and the second
prompt asks for a floating number. I am trying to send the program
"3\n" to satisfy the first prompt and ".9982\n" to satisfy the second
prompt. I am using this on windows XP with jsdk 1.4. The whole code
is:

import java.io.*;

class test {

public static void main(String[] args) throws Exception {
String numImages;
String density;
numImages = "3\n";
density = "0.9982\n";

System.out.println("creating child");

try {

Process p = Runtime.getRuntime().exec("apend.exe");

OutputStream out = p.getOutputStream();

out.write(numImages.getBytes());
out.write(density.getBytes());

p.getOutputStream().close();
p.waitFor();

System.out.println("child finished");

} catch (IOException e) {
}

}
}


If your append.exe program get the input from stdin, your code should
work. However, since your current code doesn't read prompts and
doesn't do waitFor(), it should fail.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.