从java运行bash脚本时,只执行echo语句

时间:2016-01-14 02:45:37

标签: java bash

我正在尝试从java文件运行bash脚本。该脚本仅运行echo语句,其余代码不会执行。但是,当脚本单独运行时,它可以正常工作。

Java Code: Trying to run bash script from java code

Process p3 = Runtime.getRuntime().exec(chmod 777 "/path/runall_1");
String line = "";

BufferedReader reader = new BufferedReader(new InputStreamReader(p3.getInputStream()));             

while ((line = reader.readLine())!= null) {
     output.append(line + "\n");    
}
System.out.println(output);              
p3.waitFor();


Script runall_1: Compile and run C files using script

cflag="-std=gnu99 -O3" 
rm -rf core
algorithm="fgme"
echo ${algorithm}
gcc ${cflag} -DAlgorithm=${algorithm} Newharness.c -lpthread -lm
Time="2"    
N="32"      
F="2"

rm -rf core

T="1"
while [ ${T} -le ${N} ] ; do
./a.out ${T} ${Time} ${F} # Zhang d-ary
if [ -f core ] ; then
echo core generated for ${T} ${Time} ${F}
break
fi
T=`expr ${T} + 1`
done 

if [ -f core ] ; then
echo core generated for ${1}
break
fi


Output: fgme
Build Successful...        

0 个答案:

没有答案