Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Java: writing to created processes

Java: writing to created processes
Thread Tools
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Dec 20, 2001, 12:32 AM
 
Okay, so I was kind of intersted in writing a little Cocoa-Java app that would be able to read and write to a tcsh session created by my program. Sounds easy enough. Here's what I have started:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
Process p = Runtime.getRuntime().exec(<font color = red>"tcsh"</font>);
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
</font>[/code]

That looks good to me (with all the appropriate imports and such). But when I try to call out.write(String), I can't seem to have anything done. Like, I see my tcsh session created while watching top, but if I out.write("top"), it never shows up as a new process in top. I've tried adding carriage returns and new lines to no avail. And when I try in.readLine() to see what's being printed out by tcsh, my app always locks up right there, as if the first line is infinetly long...

So, does anyone see the folly of my ways? Because I'm really confused.

Thanks,
F-bacher
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Dec 20, 2001, 12:52 AM
 
Have you flushed the buffer after the write?
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
Dec 20, 2001, 03:13 AM
 
And you always need to check your input streams before trying to read from them - or do it on a different thread. Lock-ups not nice.
All words are lies. Including these ones.
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Dec 20, 2001, 08:36 AM
 
SWEET!... half way. Okay, so I can now write to tcsh with flushing after each write, but every time I check ready on my BufferedReader, it's never ready. Am I forgetting something here? I don't see any other methods I can call off of Reader's as is...

Thanks for all your help,
F-bacher
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2