linux - Running a C file from within another C file in Ubuntu -
i need run c program within c program on ubuntu. scanf //say i=2 entered
switch (i){ case 1: print xyz; break; case 2: cc abc.c -lpthread (and then) ./a.out //execute command execute file name abc break; }
how that? searched google thoroughly couldn't find suitable answers.
edit: running said execute command bash file. works , solves requirement in easy way :d
#! /bin/bash read if [ $a -eq 1 ] cc ex.c -lpthread ./a.out else echo "hi" fi
you need make use of fork() , exec() spawn off subprocess (regardless of process doing - note you're compiling , running new process).
if want spawn off process , wait it, relying on return (error) code determine success, system()
option.
Comments
Post a Comment