Search for "java run command" to help refine the question better - e. Note that some commands do not make sense outside of a shell. These include cd and the like and should be emulated accordingly.
Although, I would likely consider it a "better" investment of time to emulate all supported commands - i. Add a comment. Active Oldest Votes. I hope this helps : You could use: Runtime. Improve this answer. Bevilacqua Bevilacqua 3 3 gold badges 8 8 silver badges 18 18 bronze badges. Take advantage of the ProcessBuilder. MadProgrammer MadProgrammer k 22 22 gold badges silver badges bronze badges.
IOException; import java. Shehan Dhaleesha 1 1 gold badge 7 7 silver badges 29 29 bronze badges. Akshay Pethani Akshay Pethani 2, 2 2 gold badges 28 28 silver badges 38 38 bronze badges. Swastik Padhi Swastik Padhi 1, 13 13 silver badges 23 23 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. You can get that with pr.
Update: I think exitValue will throw an exception if the process has not finished where as waitFor So, the output will be: Press Y if you're cool [Y,N]?
Craigo Craigo 2, 25 25 silver badges 19 19 bronze badges. You can also use p. Apologies for the confusion. Community Bot 1 1 1 silver badge. Thank you for pointing that out, I was actually struggling because I had no stderr. Igor Popov Igor Popov 9, 7 7 gold badges 50 50 silver badges 65 65 bronze badges. The shortest code is always my favorite.
Shaun Shaun 2, 19 19 silver badges 33 33 bronze badges. Denis Denis 2 2 silver badges 14 14 bronze badges. Have you tried the exec command within the Runtime class? Funky coder Funky coder 5, 2 2 gold badges 28 28 silver badges 54 54 bronze badges. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. System info bat file program output. Process process. Attention reader! Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Articles. Execute main multiple times without using any other function or condition or recursion in Java. Article Contributed By :.
Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Java.
0コメント