At the time of this writing, you can't easily find the Scala Process and ProcessBuilder classes (the Scala API documentation), so in an effort to help you (and the search engines) find those classes more easily, here are direct links to them:
Our ThreadedStreamHandler class
Based on an old-but-good article at JavaWorld, I'm developing the following Java ThreadedStreamHandler class. (It's still a work-in-progress, but as mentioned, commands that don't have to be run using
sudo seem to work just fine right now.)
I've been thinking about rewriting my old tutorial on how to execute system processes from a Java application for a while now (How to run system commands from Java applications), but it's a topic that quickly becomes complicated if you want to do it right, so I kept postponing it until I could give it some quality time in a real-world project.
A complete Java class that executes a system command
Now that you've seen that snippet of code, here's a complete Java class named ProcessBuilderExample that can execute a Unix/Linux system command: