Everything Wrong With Java, the example:<p><pre><code> try {
Process p = Runtime.getRuntime().exec(
System.getenv("windir") + "\\system32\\tasklist.exe");
BufferedReader input = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line);
//If line describes a correct process,
//reformat the string to get your information out here.
}
input.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
</code></pre>
This should read:<p><pre><code> println( System.exec( "tasklist.exe" ) );
</code></pre>
Yes, there should be a stream interface to the output, yes there should be a more complicated mechanism for working with processes in an object oriented manner, but c'mon guys: most of us just want to execute a command and screw with the string output.