Unix system command substitution in C
Posted on 2004-09-08
I wanted to write events (errors, etc) relating to a program to a logfile using the Unix command while in a C program e.g. :
case 1: /* Key error message for shared memory */
system("date >> $MYLOG | echo Error in obtaining key to shared memory!(DCSF) >> $MYLOG");
system("logger -f $MYLOG ");
Note that the $MYLOG is just to represent a logfile which in the actual case is the value of a C variable cLogFileName which is updated from a config file. (In this case, cLogFileName equals a value "../data/logfile01.dat" ). My question is how can I substitute the value of a C variable into the Unix shell command so that the Unix command appends to the physical file (in this case ../data/logfile01.dat) ??
Thanks in advance.