Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Java equivalent of Python's subprocess.Popen()?

import subprocess
import os

prefix = os.path.expanduser("~/.bin/kb/")
p = subprocess.Popen([(prefix + "koreball"),(prefix + "/data"),'3'])
like image 354
thiruvadi Avatar asked Jan 22 '23 10:01

thiruvadi


1 Answers

Your can try with the Runtime.exec method.

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("myprocess");

The method returns a Process that can be used to:

  • Retrieve the process output, input and error streams
  • Retrieve the process output code
  • Kill the process
  • Wait for the end of the process execution
like image 158
Vivien Barousse Avatar answered Jan 29 '23 13:01

Vivien Barousse