1

First of all, forgive my awful english.....

This is the prototype

FILE *popen(const char* cmd_string, const char* type);

Here is my question, the book says that when popen function is called, it will call exec to get a shell to execute the cmd_string we give to popen, but I'm not sure which shell will exec get, so can anyone give me an answer?

anonymous
  • 61
  • 7

2 Answers2

2

/bin/sh : From the doc:

   The command argument is a pointer to a null-terminated string
   containing a shell command line.  This command is passed to /bin/sh
   using the -c flag; interpretation, if any, is performed by the shell.
Maksim
  • 511
  • 5
  • 15
0

Let's try and see:

$ cat test.c
#include <stdio.h>

int main() {

  FILE *fp;
  char var[5];

  fp = popen("echo $0", "r");
  fgets(var, 5, fp);
  printf("%s", var);
}
$ gcc -Wall test.c
$ ./a.out
sh
James Brown
  • 36,089
  • 7
  • 43
  • 59