I need to run a C program from within another C program on Ubuntu. Something like scanf i //say i=2 is entered
switch (i){
case 1: print xyz;
break;
case 2: cc abc.c -lpthread (and then) ./a.out //execute this command to execute file with name abc
break;
}
How to do that? I searched Google thoroughly but couldn't find suitable answers.
Edit: I am now running the said execute command from a bash file. It works and solves my requirement in an easy way :D
#! /bin/bash
read a
if [ $a -eq 1 ]
then
cc ex.c -lpthread
./a.out
else
echo "hi"
fi
runa c program, but the example you show is talking aboutcompilinga c program. Which is it?&&after the compilation command line; that will then only run./a.outif the compiler succeeds:cc ex.c -lpthread && ./a.out(can all be on one line given that it is so short).