Exec() and leave running in background
in
Programming Questions
•
3 months ago
Hello all, maybe this is a Ubuntu shell question more than processing, but here goes.
I have some code as part of my application which executes a function "shell(
String[] params)", which calls the shell prompt with a particular command (
String[] params) on my Ubuntu machine. For example:
- String[] runTC = {
- "/bin/bash",
- "-c",
- "ipython -noconfirm_exit /home/dir1/dir2/dir3/someprogram.py arg1 arg2"
- };
- String pipeOut;
- void shell(String[] params) {
- try {
- String line;
- OutputStream stdin = null;
- Process p = Runtime.getRuntime().exec(params);
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- while ( (line = input.readLine ()) != null) {
- pipeOut = line;
- }
- input.close();
- }
- catch (Exception err) {
- err.printStackTrace();
- }
- }
Many thanks!
1