b********y 发帖数: 3 | 1 I wanna test if there is a duplicate instance running.
So, I am trying to call the following unix commands,
ps acx > ./ps_Client.txt
and
grep -c Client ./ps_Client.txt > ./grep_Client.txt
but when I try to open the file grep_Client.txt, I got the
FileNotFoundException, there is no such file at all.
The follows are my code,
String SysCommand = "ps acx > ./ps_Client.txt";
Process p = Runtime.getRuntime().exec(SysCommand);
SysCommand = "grep -c Client ./ps_Client.txt > ./grep_Client.txt";
Process p | m****r 发帖数: 11 | 2 You need to wait the 1st process terminated before spawning the 2nd process.
why not use pipe?
【在 b********y 的大作中提到】 : I wanna test if there is a duplicate instance running. : So, I am trying to call the following unix commands, : ps acx > ./ps_Client.txt : and : grep -c Client ./ps_Client.txt > ./grep_Client.txt : but when I try to open the file grep_Client.txt, I got the : FileNotFoundException, there is no such file at all. : The follows are my code, : String SysCommand = "ps acx > ./ps_Client.txt"; : Process p = Runtime.getRuntime().exec(SysCommand);
| c**g 发帖数: 274 | 3 try to use full path name.
【在 b********y 的大作中提到】 : I wanna test if there is a duplicate instance running. : So, I am trying to call the following unix commands, : ps acx > ./ps_Client.txt : and : grep -c Client ./ps_Client.txt > ./grep_Client.txt : but when I try to open the file grep_Client.txt, I got the : FileNotFoundException, there is no such file at all. : The follows are my code, : String SysCommand = "ps acx > ./ps_Client.txt"; : Process p = Runtime.getRuntime().exec(SysCommand);
| B**z 发帖数: 153 | 4 sometimes you have to go through(just do a read) all stdout and stderr
to make it work.
【在 b********y 的大作中提到】 : I wanna test if there is a duplicate instance running. : So, I am trying to call the following unix commands, : ps acx > ./ps_Client.txt : and : grep -c Client ./ps_Client.txt > ./grep_Client.txt : but when I try to open the file grep_Client.txt, I got the : FileNotFoundException, there is no such file at all. : The follows are my code, : String SysCommand = "ps acx > ./ps_Client.txt"; : Process p = Runtime.getRuntime().exec(SysCommand);
|
|