Kindly anyone help me out in doing this (as mentioned in the subject line). Tried various links on this website and on Google, but nothing is working. So, I want to store the output of C++ executable to a shell variable. Trying to do this like this:
printf '\n'
printf '\n'
printf '<h3>[Test case]</h3>'
printf '<p> Input: %s</p>' "$p"
#out=`echo $p | ./Main << EOF `
#out=`echo tamu 1 algo clrs 1234 5 1234 4 Q | ./Main`
out = "$(echo ./Main <<EOF
tamu
1
algo
clrs
1234
5
1234
4
Q
EOF)"
printf '<p> Your output: %s</p>' "$out".
But getting following error:
$ASNLIB/run_submission.sh: line 27: unexpected EOF while looking for matching `)'
$ASNLIB/run_submission.sh: line 90: syntax error: unexpected end of file.
However, indentation and braces everything is correct. Also, just doing this:
./Main << EOF
tamu
1
algo
clrs
1234
5
1234
4
Q
EOF
gives me output but I want to store this output in a shell variable for further computation. Kindly anyone let me know how to do this.
So, here is the full file:
#!/bin/bash
trap cleanup 1 2 3 6 9
cleanup()
{
echo "Critial error occurred. Program failed to run."
exit 1
}
rm -f summary.txt
let "total_score=0"
passfail="PASSED"
let "Outcome=PASSED"
printf '\n'
printf '\n'
out =`./Main <<EOF
tamu
1
algo
clrs
1234
5
1234
4
Q
EOF`
echo "Your output: "
echo $out
printf '<p>====================================================================================================</p>'
printf '\n'
printf '\n'
ref =`./Main_ref <<EOF
tamu
1
algo
clrs
1234
5
1234
4
Q
EOF`
echo "Expected output: "
echo $ref
printf '<p>====================================================================================================</p>'
python $ASNLIB/compare_string.py "$out" "$ref" > /dev/null
if [ "$?" != "0" ]; then
printf '<p style="color:red;">[FAILED.]</p>'
Outcome="FAILED"
let "total_score=0"
printf '<p><b> Outcome: %s</b></p>' "Please follow all the instructions as mentioned in the lab-work. It seems that you have missed any of the following instructions. 1) Might you have not returned the value in Library.cpp file using reference. 2) Please be ensure that you also need to change the declaration of this Library::getBook() in Library.h file."
printf '<p><b> Total Score: %s</b></p>' $total_score
else
printf '<p style="color:green;">[PASSED.]</p>'
Outcome="PASSED"
let "total_score=1"
printf '<p><b> Outcome: %s</b></p>' "Complete"
printf '<p><b> Total Score: %s</b></p>' $total_score
fi
echo "Correctness, $Outcome, $total_score, 1" >> summary.txt
I can see errors after doing changes as what is mentioned in the first comment which are as follows:
$ASNLIB/run_submission.sh: line 39: warning: here-document at line 29 delimited by end-of-file (wanted `EOF')
$ASNLIB/run_submission.sh: line 29: out: command not found
$ASNLIB/run_submission.sh: line 59: warning: here-document at line 49 delimited by end-of-file (wanted `EOF')
$ASNLIB/run_submission.sh: line 49: ref: command not found
And the output of variables - "out" and "ref" is empty.