- 论坛徽章:
- 0
|
我要在java中调用一个shell命令.
其中shell代码如下:
-------------------------------------------------
#!/bin/bash
# run command script
# rc.sh
FILE="$1"
CMD="$2"
# run command and output its PID
$CMD &
echo $! > $FILE
wait
# delete the PID
/bin/rm -f $FILE
-------------------------------------------------
其中,$1就是个文件名,用于存储PID,$2是个命令,可以带参数,比如"du -c -B M"
JAVA中这样调用
...
Process proc = Runtime.getRuntime().exec("/usr/bin/rc.sh 445.pid \"du -c -B -M\"",null,"/home/juser");
...
这里会错误提示: "du 命令没有找到
问题: 怎么让rc.sh中将du -c -B M作为一个参数传入? 就和直接在shell提示符下运行
/usr/bin 445.pid "du -c -B M"
这样的效果?
或在rc.sh中怎么修改比较好?
PS: 这个问题在shell版块发过了,没有人回复. 两个地方发会不会有问题? |
|