Passing variable from c program to shell script as argument

后端 未结 4 383
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 01:48

I am calling a shell script from a \'c\' program and have some variables in c which I would like to pass as arguments to the shell script. I tried using the system() to call

4条回答
  •  星月不相逢
    2020-12-22 02:49

    This below program have worked for me

    #include 
    #include 
    #include 
    #include 
    #include 
    int main(int argc, char const *argv[])
    {
       
    char buf[1000]; //change this length according to your arguments length
      
      int i;
      for (i=0;i

    My Shell script had arguments like

    sh shell-scriptname.sh -a x -b y -c z -d blah/blah/blah

    I complied the C program using the following

    gcc c-programname.c -o utility-name

    To execute

    ./utility-name -a x -b y -c z -d blah/blah/blah

    worked for me

提交回复
热议问题