Skip to main content

Write to stdin

3 replies [Last post]
Joined: 2006-05-05

How can I write to stdin? I execute a 3rd party library and it prompts for password on the console. There's not going to be anyone around to type in the password so I need to do it from code.

What's the standard way of doing this? Do I have to spawn a new process and use a pipe?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-04-23

If you're executing the 3rd party library using Runtime.exec(...), then you're getting back a Process object. Call the Process.getOutputStream() method and start writing to it, this is the input stream from the 3rd party program's pov.

Joined: 2006-05-05

Thanks, that works even if it does suck because I have limited interaction with the new process.

I tried using System.setIn() and a PipedInput/OutputStream but somehow the 3rd party library does not use the new

Joined: 2006-12-18

Perhaps a new thread will suffice. has a Pipe that may be useful to you. Then use a new thread to write down the pipe to stdin.

Just a wild stab in the dark, but perhaps you could use PushbackInputStream? Something along the lines of:
PushbackInputStream pushIn = new PushbackInputStream(;

Looks kinda hackish and may plain not work at all, but it's a thought. :)