running shell script using c programming

前端 未结 3 1850
北海茫月
北海茫月 2021-01-25 23:56

hello every one I want to ask that I am making a program in which i have to run shell script using c program. up till now i have separated the arguments. and i have searched tha

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 00:19

    Running a shell script from a C program is usually done using

    #include 
    int system (char *s);
    

    where s is a pointer to the pathname of the script, e.g.

    int rc = system ("/home/username/bin/somescript.sh");
    

    If you need the stdout of the script, look at the popen man page.

提交回复
热议问题