run shell command inside of c code?
in one directory, i have cpc.c and cource file
cpc.c is : #include<stdio.h> #include<stdlib.h> main() { system("/bin/sh -c cp source dest"); } i want copy source file to dest file, but there is no dest file. when i execute cpc by type ./cpc, there is something error like "cp: missing file arguments". how about that? thank's |
Hi
The correct prog is following cpc.c is : #include<stdio.h> #include<stdlib.h> main() { system("/bin/sh \"-c cp source dest\""); } as -c option take the single input string as argument in shell.so multiple strings must be quoted |
Why so difficult?
According to "man system": Quote:
Code:
#include <stdlib.h> |
All times are GMT -5. The time now is 12:06 AM. |