From a java program, I want to execute a script which reads an input from a specified folder and generates gcov data. The script generates part of the gcov data correctly, but fails to generate the remaining data until I explicitely terminate my java program, after which it completes its job as expected.
Here is the code that launches the script:
try {
Process proc = Runtime.getRuntime().exec("/bin/bash CovSeq.sh");
proc.waitFor();
System.out.println("Generated gcov Data");
} catch(Exception e) {
System.err.println("Error: "+e.getMessage());
}
Here is the script:
#!/bin/bash
lines=($(cat path))
mkdir output
mkdir gcovOut
rm -f -r ./gcovOut/*
rm -f -r ./output/*
gcc -g -o temp_exec -fprofile-arcs -ftest-coverage ${lines[0]}
path1=`pwd`
cd ${lines[1]}
for i in `ls *`
do
cd $path1
./temp_exec < ${lines[1]}/$i > ./output/$i
gcov -b -c ${lines[0]}
mkdir ./gcovOut/$i
mv *.gcov ./gcovOut/$i
mv *.gcda ./gcovOut/$i
cd ${lines[1]}
done
My bet is that the script is blocked because the parent process does not consume its output. This is known behaviour for
Runtime.exec(). Here is an example how to use it properly.