Shell commands
| End-of-stream | Kill application | Suspend app and return to shell | |
| Unix | Ctrl-D | Ctrl-C | Ctrl-Z |
|
Windows (DOS prompt) |
Ctrl-Z [Enter] | Ctrl-C | No such command |
I have read a lot about Java but one of the things I rarely see discussed is how you should go about running external system commands.
Of course, you probably do not read much about this because it takes away from the portability of Java applications.
For instance, if you write a Java application on a Unix system, you might be interested in running the "ps -ef" command, and reading the output of the command. For Unix systems this is great however, this same program will not work on a Windows system because the ps command isn't available on Windows.
Putting portability aside for this article, we will demonstrate a method that can be used to run system commands.
Of course, you probably do not read much about this because it takes away from the portability of Java applications.
For instance, if you write a Java application on a Unix system, you might be interested in running the "ps -ef" command, and reading the output of the command. For Unix systems this is great however, this same program will not work on a Windows system because the ps command isn't available on Windows.
Putting portability aside for this article, we will demonstrate a method that can be used to run system commands.
