Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making python like system calls in java

Is there an equivalent to Python's popen2 in Java?

like image 771
dave Avatar asked Dec 13 '25 07:12

dave


2 Answers

I believe the Process object is what you're looking for. Javadoc here. You use it something like Process myProcess = System.getRuntime().exec("cmd here")); It allows you to get the standard and error output streams.

like image 193
Poindexter Avatar answered Dec 14 '25 19:12

Poindexter


System.getRuntime().exec(...)

System.getRuntime() yields the Runtime object, from which you can make various .exec(...) calls that spawn a Process object. This has input and output streams and a status.

like image 35
relet Avatar answered Dec 14 '25 19:12

relet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!