bash - C system() call parameter expansion -
i'm trying merge set of files using c system()
call:
int main(int argc, char* argv[]) { return system("cat output{1,2} > merged.out"); }
the result is:
$ gcc test.c $ ./a.out cat: output{1,2}: no such file or directory
it works if directly in bash:
$ ls output{1,2} output1 output2 $ cat output{1,2} 1,2 3,4
how can enable parameter expansion in system()
call?
the reason system
uses /bin/sh
, not expand braces. instance, try:
/bin/sh -c 'echo cat output{1,2}'
and compare
/bin/bash -c 'echo cat output{1,2}'
if must, like
system("/bin/bash -c 'cat output{1,2} > merged.out'");
but why not read both files , write output merged.out
?
Comments
Post a Comment