就两行? $1 $2参数没传入也不影响吗? chmod +x test2.sh 直接Process pcs=rt.exec("test2.sh");试试看 难不成发生了process的死锁? javadoc的Process的说明的倒数第三段的最后一句话有关于死锁方面的说明Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
运行失败有什么错误提示吗?
test2.shDIRNAME=`dirname $0`
gpg --passphrase-fd 0 --yes -o $2 -d $1 < $DIRNAME/Password.txt没有提示
是sh 还是 ksh 或者其他的?
$1 $2参数没传入也不影响吗?
chmod +x test2.sh 直接Process pcs=rt.exec("test2.sh");试试看
难不成发生了process的死锁?
javadoc的Process的说明的倒数第三段的最后一句话有关于死锁方面的说明Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
Linux jp_home6 2.4.21-51.EL3.customsmp #1 SMP Fri Jun 27 10:44:12 CST 2008 i686 i686 i386 GNU/Linux[admin@jp_home6 bops]$ echo $0
/bin/bash
throw new Exception("the arg cmd is null");
}
Process process = null;
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String s = null;
try {
//TODO debug 改成linux
process = Runtime.getRuntime().exec(cmd);
//process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", cmd });
//process = Runtime.getRuntime().exec("cmd /C start /min "+ cmd );
log.error("====cmd===start==== "+ cmd);
br = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((s = br.readLine()) != null) {
sb.append(s).append("\n");
}
log.error("====cmd===end======================= ");
log.error("====result:======="+sb.toString());
//if(doSynchrony){
//process.wait();
//}
return sb.toString();
// }catch(InterruptedException e){
// log.error("execute cmd error,processes was interrupted, cmd: " + cmd);
// throw e;
}
catch(Exception e){
log.error(e);
throw e;
}
finally {
if (process != null) {
process.destroy();
}
process = null;
if (br != null) {
try {
br.close();
} catch (Exception e) {
throw e;
}
br = null;
}
}
执行后return sb.toString();返回的信息是什么?
/usr/local/bin/gpg --no-tty --passphrase-fd 0 --yes -o $2 -d $1 < /home/admin/bops/Password.txt 2> /tmp/temp.txt现在解决了。C环境找不到/dev/tty运行的时候加了 --no-tty 谢谢各位了