Home > database >  How to wait for C program to finish executing in bash script Readme file
How to wait for C program to finish executing in bash script Readme file

Time:11-23

I am new to bash scripting and I am trying to create a Readme file that will run a c program. The C program works fine and all it does is take user input, do calculations and display the result. How would I write a bash script which would wait for the user input and only remove the a.out after the result of my calculation has been printed on the console. I know I would have to use a while loop but how would I exit the while loop once my C program has finished and printed the result. I thought of including a sleep instruction but I wouldn't know how long the user could take to enter multiple inputs. Mind you my C program accepts multiple inputs; not just one. The current script I have doesn't allow me to take user input:

#!/bin/bash

echo "C PROGRAM STARTED"
make -f Makefile all
pid = $!
wait $pid 
echo "END OF PROGRAM"
make -f Makefile clean

This is the result I get:

C PROGRAM STARTED
cc thread3520.c -lpthread -o ptf
END OF PROGRAM
rm ptf

CodePudding user response:

The Makefile creates the executable, it doesn't execute it. Call the created executable before running make clean.

  • Related