Trying to avoid the batch file route

D

Danger_Duck

The code is pretty self explanatory-the commented out portion does not
work I'm guessing due to the ">" which the java runtime does not
recognize?

How do I write the output to a text file without having to use a batch
file? Things would be nice if exec() returned the output, but the
process which is returned does not do so to my knowledge. So, I try
what typically is done on command prompt.

Thanks in advance.

private String createMapFile(String binDirectory, String binName) {
// String mapCommand = "nm -t d " + binDirectory + "/" + binName + "
" + binDirectory + "/mapFile.txt";
// Process proc;
// try {
// proc = Runtime.getRuntime().exec(mapCommand);
// proc.waitFor();
// System.out.println("Exit value = " + proc.exitValue());
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
//use batch file to write into mapFile.txt:

File f = new File(binDirectory + "temp.bat");

PrintWriter p;
try {
p = new PrintWriter(f);
p.println();
p.close();
Process proc = Runtime.getRuntime().exec(binDirectory +
"temp.bat");
proc.waitFor();
System.out.println("Exit value = " + proc.exitValue());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

f.delete();

return binDirectory.concat("/mapFile.txt");
}
 
T

Thomas Kellerer

Danger_Duck wrote on 28.08.2008 22:30:
How do I write the output to a text file without having to use a batch
file? Things would be nice if exec() returned the output, but the
process which is returned does not do so to my knowledge. So, I try
what typically is done on command prompt.

Did you try to use Process.getInputStream() or Process.getErrorStream() to read
the process' output?

Quote from the Javadocs:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html

"All its standard io (i.e. stdin, stdout, stderr) operations will be redirected
to the parent process through three streams (getOutputStream(),
getInputStream(), getErrorStream())"


http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html#getInputStream()

"Gets the input stream of the subprocess. The stream obtains data piped from the
standard output stream of the process represented by this Process object."
 
M

Mike Schilling

Eric said:
[*] IMHO the names getInputStream() and getOutputStream() are
poorly assigned and a source of confusion. Too late to fix them
now, of course: It's dam under the water.

Yeah, it's a damned shame that getProcessOutput() and
getProcessInput() are illegal Java method names.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top