running shell script using c programming

前端 未结 3 1821
北海茫月
北海茫月 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条回答
  •  鱼传尺愫
    2021-01-26 00:05

    #include 
    #include 
    
    #define SHELLSCRIPT "\
    for ((i=0 ; i < 10 ; i++))\n\
    do\n\
    echo \"Count: $i\"\n\
    done\n\
    "
    
    int main(void)
    {
      puts("Will execute sh with the following script:");
      puts(SHELLSCRIPT);
      puts("Starting now:");
      system(SHELLSCRIPT);
      return 0;
    }
    

    Reference: http://www.unix.com/programming/216190-putting-bash-script-c-program.html

提交回复
热议问题