I am having some strange problems with this.
We use the Xvfb Virtual Desktop Manager and want it to work before I continue. Using a clean shell, I could do it easily:
ps -ef | grep Xvfb | grep -v grep
And that gives me exactly what I need, one line containing information about Xvfb progress. Then I want to include this in my Java program and analyze the results and save the PID of the running Xvfb process. Therefore, I try:
String line; try { Process p = Runtime.getRuntime().exec("ps -ef | grep Xvfb | grep -v grep"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } } catch (Exception err) { System.out.println(err); }
The bizarre thing is that if I use "ps -ef", I get a huge list of processes that are dumped to the console when my application starts. But if I use | grep, to narrow the list of returned processes, I get null results. input.readLine () gets null each time.
I also tried:
ps -ef | grep Xvfb | grep -v grep | awk {'print $2'}
To just grab the process id. Also, no luck.
Has anyone else experienced this or knew what I was doing wrong?
source share