哪个 shell 将在调用 popen 时执行 cmd
Which shell will execute the cmd when popen is called
首先,请原谅我糟糕的英语.....
这是原型
FILE *popen(const char* cmd_string, const char* type);
这是我的问题,书上说调用popen函数的时候会调用exec得到一个shell来执行我们给popen的cmd_string,但是我没有确定哪个 shell 会执行,所以有人能给我答案吗?
/bin/sh :来自文档:
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.
我们试试看:
$ cat test.c
#include <stdio.h>
int main() {
FILE *fp;
char var[5];
fp = popen("echo [=10=]", "r");
fgets(var, 5, fp);
printf("%s", var);
}
$ gcc -Wall test.c
$ ./a.out
sh
首先,请原谅我糟糕的英语.....
这是原型
FILE *popen(const char* cmd_string, const char* type);
这是我的问题,书上说调用popen函数的时候会调用exec得到一个shell来执行我们给popen的cmd_string,但是我没有确定哪个 shell 会执行,所以有人能给我答案吗?
/bin/sh :来自文档:
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.
我们试试看:
$ cat test.c
#include <stdio.h>
int main() {
FILE *fp;
char var[5];
fp = popen("echo [=10=]", "r");
fgets(var, 5, fp);
printf("%s", var);
}
$ gcc -Wall test.c
$ ./a.out
sh