Okay, got a GUI program that runs a ping on a selected machine to see if its alive. I would like to have the responses show up in the JTextArea that I have. How can I get that done? If I run it now, I can't even see the command run in the DOS window, but I think that's because when you use: Runtime.getRuntime().exec("...the command stuff here..."); the output defaults to stderr. (I think I remember reading that somewhere...) If that is the case, how do I change where the output shows up? I know I can port the output to a file and then read it in, but shouldn't there be a way to write it directly to the window?? Ryan P.S. Just upgraded to Ranch Hand --- YeeeHaw!! 8)
Ryan Headley<br /><a href="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>
The program you are calling is what determines which stream it is writing to. Most applications write to stdout. A few (and javac is one of them) write to the err stream. Ping does not on win32. To do this, you create an input stream off the process that Runtime.exec returns and read the response. Example :
Carl, you are the freakin' Wyatt Earp of the JavaRanch! That is the coolest thing I have seen in a month! I used your code fragment to execute cmd on my NT machine. Then I added a line to capture the output stream for the process and sent "dir *.java" to it. Sure enough, I saw the listing in my application's output window. Now I can do anything I want to in DOS and my java application sits on top of the process and monitors the I/O. I am LOVING this! [This message has been edited by Nick Riviera (edited November 13, 2000).]
Joined: Jun 28, 2000
WOW!! That's pretty sweet. I obviously need to make my GUI multi-threaded, but that's another ball game. I just wanna get the basics down first. I must ask however, why do you put the commands into an array of Strings?? Will I need to do that?? What I need to do is select the machine name from a list and then feed it to ping. So could just do a: String s = t1.getSelectedText(); And then feed s into that array?? (assuming t1 is my JTextField). Also, is there anyway to update the JTextArea as is happens, (no big deal just curious). What happens currently is the command runs, then places the output on the textarea. Is there anyway to make it "real time" so that you see the output happening?? Thanx again!
Originally posted by ryan headley: Also, is there anyway to update the JTextArea as is happens, (no big deal just curious). What happens currently is the command runs, then places the output on the textarea. Is there anyway to make it "real time" so that you see the output happening??