0

I am trying to start a new process using Runtime.exec(), but my problem lies within using ssh to remote in and then run a java program there. Code:

test = "ssh -t username@host java packageName.ClassName portNumber (Other command line args for this class)"
Process proc = Runtime.getRuntime().exec(new String[] {"/bin/bash", "-c", test});

this doesn't fail or catch, but I need to be able to see the stdout for the newly running process and I don't.

Note: if I run ssh -t username@host java packageName.ClassName portNumber (Other command line args for this class) from the command line it works fine. I have the host setup to not require a password by using ssh keys.

Any ideas?

3 Answers 3

2

You need to use Process.getInputStream to obtain the output from the sub-process being created.

See this article for a good discussion on Runtime.exec.

Sign up to request clarification or add additional context in comments.

Comments

1

I think you can ask for an input stream that corresponds to the stdout of the process and then print it on your standard output. If you need to see it after it executes, just call waitFor() method on the process so it finishes before you start printing.

Comments

1

Use getInputStream() to access returned process's stdout. You can also use facilities provided by ProcessBuilder.Redirect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.