Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running a command through java to the host terminal

Status
Not open for further replies.

bos

Technical User
Oct 1, 2002
50
US
The code I entered is as follows:

try {
Runtime update = Runtime.getRuntime();
Process process = update.exec("Devcom > /home/smsh/target");
//the above command on AIX should put the output of the Devcom program into a file named target.
InputStream smin = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(smin));
while ((sminput = smreader.readLine()) != null) {
System.out.println(input);
}

The problem is that the Devcom program is run and the output is displayed on a terminal yet it is not sent to the proper file as it should with the command above. Does that command need to be rewritten in any way to work right? Please let me know. Thanks in advance.
 
Put this in a shell script and execute the script from
java or run the Devcom program as you are from java
and catch the output and write it to the file from java.

For some reason I've found that complex ( piping , redirect
etc.) shell commands don't seem to work so well in this
way.

The proper way would be to run the Devcom program and catch
the output and store it wherever you want. (Instead of
System.out'ing it) It could be that the shell gets something
from the terminal when you run a command that it doesn't
when execting a command outside a term. Perhaps take a look
at the man pages for bash or korn or whatever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top