Skip to content

Instantly share code, notes, and snippets.

@Spitfire1900
Last active April 13, 2016 13:59
Show Gist options
  • Save Spitfire1900/4093e2d0bbd80a018f1f to your computer and use it in GitHub Desktop.
Save Spitfire1900/4093e2d0bbd80a018f1f to your computer and use it in GitHub Desktop.
Inherit the io of a subprocess in Java, allowing you to talk through Java to the process in the shell like normal.
import java.lang.ProcessBuilder;
import java.lang.ProcessBuilder.Redirect;
public class TestProcessBuilder
{
public static void main(String args[])
{
try
{
ProcessBuilder builder = new ProcessBuilder("fairymax");
builder.redirectInput(Redirect.INHERIT);
builder.redirectOutput(Redirect.INHERIT);
builder.redirectError(Redirect.INHERIT);
Process subProcess = builder.start();
subProcess.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment