Re: redirecting stdin, stdout in java applications

Discussion in 'Java' started by Sudsy, Jul 18, 2003.

  1. Sudsy

    Sudsy Guest

    h113862@_NOSPAM_hotmail.com wrote:
    > hi,
    >
    > question: in my C/UNIX days, i created a server program that would accept
    > incoming connections, then fire up an application and connect the
    > application's stdin and stdout to the network connection. the benefit of
    > this was that the applications could read and write to stdin/stdout and
    > would never know they were connected to a remote destination. makes
    > development easy.
    >
    > i would like to do this in java, using a super server-type program, that
    > loads a nominated class then attaches its' stdin and stdout to the incoming
    > network connection. it looks like the setIn and setOut methods of the System
    > class are ideal. but in reality, they can't be used because they appear to
    > change the stdin and stdout for everything, which means that no more than
    > one connection at a time will work.
    >
    > is there another way to do this?


    Assuming that you create a new Thread for each incoming connection
    and you're using a Runtime.exec variant to fire up the subprocess,
    do a getInputStream()/getOutputStream() on the Socket and Process.
    Using nio, anything arriving on the Socket input stream gets sent
    to the Process input stream and anything arriving on the process
    output stream goes to the socket output stream.
    Not too much different from UNIX/C except that you don't have the
    luxury of the dup2() system call.
    Sudsy, Jul 18, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael McGarry

    Redirecting stdin/stdout to a GUI widget

    Michael McGarry, Dec 17, 2004, in forum: C++
    Replies:
    5
    Views:
    526
    Michael McGarry
    Dec 18, 2004
  2. Jan Knop
    Replies:
    4
    Views:
    1,041
    Jan knob
    Nov 24, 2003
  3. Matthew Thorley

    Redirecting stdout and stdin

    Matthew Thorley, Mar 4, 2004, in forum: Python
    Replies:
    2
    Views:
    756
    Donn Cave
    Mar 4, 2004
  4. Michael McGarry
    Replies:
    1
    Views:
    606
    Michael Fuhr
    Dec 16, 2004
  5. Jan Danielsson

    Redirecting stdin/stdout to self

    Jan Danielsson, Jan 23, 2006, in forum: Python
    Replies:
    3
    Views:
    532
    Dan M
    Jan 24, 2006
Loading...

Share This Page