c语言中调用shell脚本
来源:互联网 发布:淘宝店铺图片轮播尺寸 编辑:程序博客网 时间:2024/05/21 20:28
C程序调用shell脚本共有三种方式:system()、popen()、exec系列函数
1)system(shell命令或shell脚本路径);
2)popen(char *command,char *type)
例:C程序popentest.c内容如下:
履行 效果 如下:
[root@localhost test]$ vim popentest.c
[root@localhost test]$ gcc popentest.c -o popentest
[root@localhost test]$ ./popentest
/root/test
[root@localhost test]$
(3)exec用被执行的程序完全替换调用它的程序的影像。fork创建一个新的进程就产生了一个新的PID,exec启动一个新程序,替换原有的进程,因此这个新的被exec执行的进程的PID不会改变,和调用exec函数的进程一样。
程序例:
/* execv example */
#include <process.h>
#include <stdio.h>
#include <errno.h>
void main(int argc, char *argv[])
{
int i;
printf("Command line arguments:\n");
for (i=0; i<argc; i++)
printf("[%2d] : %s\n", i, argv[i]);
printf("About to exec child with arg1 arg2 ...\n");
execv("CHILD.EXE", argv);
perror("exec error");
exit(1);
}
- c语言中调用shell脚本
- C语言调用SHELL脚本
- C语言中system调用shell脚本的问题
- c语言中调用shell脚本返回值问题分析
- c语言中调用shell脚本返回值问题分析
- 在C语言中调用Unix Shell脚本。
- c语言中调用shell脚本的三种方式
- c语言中调用shell脚本返回值问题分析
- C中调用shell 脚本
- c语言调用shell脚本或命令
- android C 中调用SHELL脚本
- linux C中调用shell命令和运行shell脚本
- linux C中调用shell命令和运行shell脚本
- linux C中调用shell命令和运行shell脚本
- linux C中调用shell命令和运行shell脚本
- linux C中调用shell命令和运行shell脚本
- 【编程语言】C中调用Python脚本
- c语言中调用Linux脚本
- linux基础--开机自启动
- 设置QPushButton的背景图片(或者Window、WindowText等的背景图片/颜色)
- Perl语言学习笔记 14 字符串与排序
- How to Mock Singletons in 3 Simple Ways
- ACM 139. [USACO Feb08] 麻烦的聚餐(dp+递推)
- c语言中调用shell脚本
- POJ—3069—Saruman's Army—【贪心】
- Max Points on a Line
- Codeforces Round #262 (Div. 2)B. Little Dima and Equation
- c++学习论坛
- IOS中定时器NSTimer的开启与关闭
- JAVA文件读写输入输出流关闭问题、JAVA垃圾回收
- LeetCode刷题笔录Permutations II
- selinux ObjectClassesPerms