I
iksrazal
Hi all,
I was looking at a problem at comp.os.linux.misc - trying to put
'pgrep' thru 'wc -w' . Allow the code below to explain:
package org.client;
import java.util.*;
import java.io.*;
public class Pgrep {
public static void main(String[] args) {
try {
// String[] cmd = new String[]{"sh", "-c", "/usr/bin/pgrep
-f konqueror | /usr/bin/wc -w"
// String[] cmd = new String[]{"sh", "-c", "/usr/bin/pgrep
-f konqueror"
String[] cmd = new String[]{"sh", "-c", "/usr/bin/pgrep -f
konqueror | od -c"
};
System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
// put a BufferedReader on the ls output
InputStream inputstream =
proc.getInputStream();
InputStreamReader inputstreamreader =
new InputStreamReader(inputstream);
BufferedReader bufferedreader =
new BufferedReader(inputstreamreader);
// read the ls output
String line;
while ((line = bufferedreader.readLine())
!= null) {
System.out.println(line);
}
// check for failure
if (proc.waitFor() != 0) {
System.err.println("exit value = " +
proc.exitValue());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/home/iksrazal/ahelp> ps -ef | grep [k]onqueror
iksrazal 23848 7744 0 Mar14 ? 00:01:05 konqueror [kdeinit]
konqueror --silent
iksrazal 29474 7744 0 Mar14 ? 00:00:00 kio_file [kdeinit]
kio_file file /tmp/ksocket-iksrazal/klauncherkxpgOb.slave-socket
/tmp/ksocket-iksrazal/konquerorRuDO7b.slave-socket
/home/iksrazal/ahelp> /usr/bin/pgrep -f konqueror | wc -w
2
Running from the above program - with the command above running 'wc -w'
I get 3. Running the version with 'od -c' I get:
[echo] running grep
[java] sh -c /usr/bin/pgrep -f konqueror | od -c
[java] 0000000 2 3 8 4 8 \n 2 9 4 7 4 \n 1
7 8 2
[java] 0000020 7 \n
[java] 0000022
With the content after '23848' and '29474' changing with every
invokation.
Any ideas?
Robert
http://www.braziloutsource.com/
I was looking at a problem at comp.os.linux.misc - trying to put
'pgrep' thru 'wc -w' . Allow the code below to explain:
package org.client;
import java.util.*;
import java.io.*;
public class Pgrep {
public static void main(String[] args) {
try {
// String[] cmd = new String[]{"sh", "-c", "/usr/bin/pgrep
-f konqueror | /usr/bin/wc -w"
// String[] cmd = new String[]{"sh", "-c", "/usr/bin/pgrep
-f konqueror"
String[] cmd = new String[]{"sh", "-c", "/usr/bin/pgrep -f
konqueror | od -c"
};
System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
// put a BufferedReader on the ls output
InputStream inputstream =
proc.getInputStream();
InputStreamReader inputstreamreader =
new InputStreamReader(inputstream);
BufferedReader bufferedreader =
new BufferedReader(inputstreamreader);
// read the ls output
String line;
while ((line = bufferedreader.readLine())
!= null) {
System.out.println(line);
}
// check for failure
if (proc.waitFor() != 0) {
System.err.println("exit value = " +
proc.exitValue());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
From the shell I have:
/home/iksrazal/ahelp> ps -ef | grep [k]onqueror
iksrazal 23848 7744 0 Mar14 ? 00:01:05 konqueror [kdeinit]
konqueror --silent
iksrazal 29474 7744 0 Mar14 ? 00:00:00 kio_file [kdeinit]
kio_file file /tmp/ksocket-iksrazal/klauncherkxpgOb.slave-socket
/tmp/ksocket-iksrazal/konquerorRuDO7b.slave-socket
/home/iksrazal/ahelp> /usr/bin/pgrep -f konqueror | wc -w
2
Running from the above program - with the command above running 'wc -w'
I get 3. Running the version with 'od -c' I get:
[echo] running grep
[java] sh -c /usr/bin/pgrep -f konqueror | od -c
[java] 0000000 2 3 8 4 8 \n 2 9 4 7 4 \n 1
7 8 2
[java] 0000020 7 \n
[java] 0000022
With the content after '23848' and '29474' changing with every
invokation.
Any ideas?
Robert
http://www.braziloutsource.com/