How to set an environment variable when using system() to execute a command?

前端 未结 3 1802
难免孤独
难免孤独 2021-01-19 05:41

I\'m writing a C program on Linux and need to execute a command with system(), and need to set an environment variable when executing that command, but I don\'t

3条回答
  •  时光说笑
    2021-01-19 05:59

    Use setenv() api for setting environment variables in Linux

    #include   
    int setenv(const char *envname, const char *envval, int overwrite);
    

    Refer to http://www.manpagez.com/man/3/setenv/ for more information.

    After setting environment variables using setenv() use system() to execute any command.

提交回复
热议问题