由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - help on "call a unix command in java"
相关主题
如何用Java去调用一个可执行的C程序?Eclipse一问
菜鸟请教个hadoop streaming job 的问题 (转载)牛人能不能给通俗地解释一下CGI?
read from multiple inputstreams at the same time?新手问个简单问题 System.out
Runtime.exec()是blocking的吗?a stupid mistake I made
[请教]调用外部命令编码的问题pipe & filter 问题
java.lang.OutOfMemoryError: Java heap space in DB queryerror of unix redirecting command called by java
[提问] The JVM could not be startedhow to use grep/sed to remove newlines? (转载)
请教一个问题,thanks!Re: Client-Server and actionPerformed
相关话题的讨论汇总
话题: client话题: txt话题: grep话题: ps话题: syscommand
进入Java版参与讨论
1 (共1页)
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);

1 (共1页)
进入Java版参与讨论
相关主题
Re: Client-Server and actionPerformed[请教]调用外部命令编码的问题
Re: real time control in javajava.lang.OutOfMemoryError: Java heap space in DB query
BBS CLIENT 不需要中文系统 v0.0.0.0.00001[提问] The JVM could not be started
Java Telnet Client Implementation v0.991Beta请教一个问题,thanks!
如何用Java去调用一个可执行的C程序?Eclipse一问
菜鸟请教个hadoop streaming job 的问题 (转载)牛人能不能给通俗地解释一下CGI?
read from multiple inputstreams at the same time?新手问个简单问题 System.out
Runtime.exec()是blocking的吗?a stupid mistake I made
相关话题的讨论汇总
话题: client话题: txt话题: grep话题: ps话题: syscommand