I am executing some commands from the command line in my java program, and it seems that this does not allow me to use "grep"? I tested this by removing the “grep” part, and the command works just fine!
My code that DOES NOT work:
String serviceL = "someService";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("chkconfig --list | grep " + serviceL);
Code that works:
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("chkconfig --list");
Why is this? And is there any correct method or workaround? I know that I can just parse all the output, but it would be easier for me to do all this from the command line. Thank.
source
share