0

I would like to call a unix system command in java code, I write code like this:

String cmd = "split -a -d -b 10M test.txt";

Process execProc = Runtime.getRuntime().exec(cmd);

I hope when the external command is finished, I could continue to execute the following program. How to implement it?

1 Answer 1

2

Try

execProc.waitFor();

This should block until the command is finished. Also maybe you should consider using ProcessBuilder, it offers much more convenient API for handling processes.

ProcessBuilder builder = new ProcessBuilder(command);
Process process = builder.start();
process.waitFor();
InputStream stream = process.getInputStream();
Sign up to request clarification or add additional context in comments.

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.