Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Do I need to close stream and how when use Runtime.getRuntime().execdirectly?

Reply
Thread Tools

Do I need to close stream and how when use Runtime.getRuntime().execdirectly?

 
 
yuanyun.ken
Guest
Posts: n/a
 
      10-30-2008
occasionally, after a long period, our product throws "Too many open
files".
So I want to make sure the code closes all stream after having used
it.

And from http://www.vnoel.com/Computers-Relat...pen-files.html,
http://www.velocityreviews.com/forum...a-process.html

I see Runtime.getProcess() method automatically opens three streams
(stdout, stderr, stdin) each time the getProcess() is called. It is
the responsibility of the caller to close those streams when done.

But if I just call it directly like this:
Runtime.getRuntime().exec("chmod 777 " + getFileName());
and doesn't get the returned Process and doesn't call
process.getInputStream()
Do I still need to close stream and how?

Any help is appreciated.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-30-2008
On Thu, 30 Oct 2008 03:16:53 -0700 (PDT), "yuanyun.ken"
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>Do I still need to close stream and how?


see http://mindprod.com/jgloss/exec.html
see sample code for how to close. Scan for "close".
--
Roedy Green Canadian Mind Products
http://mindprod.com
A vote for McCain is fearful clinging to McSame.
A vote for Obama is a shot at Obamalot.
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      11-02-2008
yuanyun.ken wrote:
> occasionally, after a long period, our product throws "Too many open
> files".
> So I want to make sure the code closes all stream after having used
> it.
>
> And from http://www.vnoel.com/Computers-Relat...pen-files.html,
> http://www.velocityreviews.com/forum...a-process.html
>
> I see Runtime.getProcess() method automatically opens three streams
> (stdout, stderr, stdin) each time the getProcess() is called. It is
> the responsibility of the caller to close those streams when done.
>
> But if I just call it directly like this:
> Runtime.getRuntime().exec("chmod 777 " + getFileName());
> and doesn't get the returned Process and doesn't call
> process.getInputStream()
> Do I still need to close stream and how?


Good question.

I would expect "no".

But I doubt that it is specified anywhere.

If you want to know for a specific implementation then check
the source.

If I look at the ProcessImpl class for SUN Java 1.6 then it
looks as if one should get the streams and explicit close
them.

Arne
 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      11-03-2008
yuanyun.ken wrote:
> But if I just call it directly like this:
> Runtime.getRuntime().exec("chmod 777 " + getFileName());
> and doesn't get the returned Process and doesn't call
> process.getInputStream()
> Do I still need to close stream and how?


Yes. You need to close all three streams. You also need to wait for the
child process, otherwise it becomes a zombie.
 
Reply With Quote
 
yuanyun.ken
Guest
Posts: n/a
 
      11-04-2008
Thanks for all the great replies , these help me a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting 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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to close a TCP socket? (TCPSocket#close doesn't close it) I├▒aki Baz Castillo Ruby 7 01-12-2010 01:32 PM
Why should close() close the underlying stream? Xiao Ma Java 16 10-27-2007 05:11 PM
what is the different between byte stream and character stream? dolphin Java 6 03-18-2007 01:58 PM
Do I need to close Reader if I close the Connection? tshad ASP .Net 1 09-06-2006 12:15 AM



Advertisments