- 论坛徽章:
- 0
|
再把里面的shell命令换成从网络上抄来的hello perl脚本(我不会perl-_-!):
myp.pl- #!/usr/bin/perl
- printf "helo,perl!\n"
复制代码 popen1.c- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- FILE *read_fp;
- char buffer[BUFSIZ + 1];
- int chars_read;
- memset(buffer, '\0', sizeof(buffer));
- read_fp = popen("./myp.pl", "r");
- if (read_fp != NULL) {
- chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
- if (chars_read > 0) {
- printf("Output was:-\n%s\n", buffer);
- }
- pclose(read_fp);
- exit(EXIT_SUCCESS);
- }
- exit(EXIT_FAILURE);
- }
复制代码 下面是命令输出
[mgqw@localhost Desktop]$ ./myp.pl
helo,perl!
[mgqw@localhost Desktop]$ cc popen1.c
[mgqw@localhost Desktop]$ ./a.out
Output was:-
helo,perl! |
|