fork download
  1. #include <stdio.h>
  2. #include <sys/wait.h>
  3. #include <unistd.h>
  4.  
  5. const char* bash_script = "printf '%s\n' \"First argument: $1\" \"Second argument: $2\"";
  6.  
  7. int main(void) {
  8.  
  9. int pid = fork();
  10. if (pid == 0) {
  11. execlp("bash", "bash", "-c", bash_script, "bash", "Argument One", "Argument Two", NULL);
  12. } else {
  13. int exit=0;
  14. waitpid(pid, &exit, 0);
  15. printf("Shell exited with status: %d\n", exit);
  16. }
  17. }
  18.  
Success #stdin #stdout 0s 19632KB
stdin
Standard input is empty
stdout
First argument: Argument One
Second argument: Argument Two
Shell exited with status: 0