//child.c
//write by swords
//2005.3.14
#include<stdio.h>
#include<stdio.h>
void main(int argc,char *argv[],char *env[])
{
printf("command line:\n ");
while(*argv)
puts(*argv++);
printf("Environment entries:\n");
while(*env)
puts(*env++);
}
//调用child.exe
#include<process.h>
#include<stdio.h>
void main()
{
printf("about to call child process\n\n");
spawnl(P_WAIT,"child.exe","child","aaa","bbb","ccc",NULL);
printf("\n\nback from child process!!!!!!!\n");
}
/*一、system(char *command)函数。功能是执行一个MS-DOS命令,它通过MS-DOS的命令解释程序COMMAND.COM,
来执行参数command字串中要求的命令,所以内存中会重新加载一份COMMAND.COM。例如可以在程序中用语句:
system(2command.com2)来实现MS-DOS的shell功能。
二、exec类函数。这类函数执行成功后子进程将覆盖父进程,这样在自己的程序中调用外部程序执行成
功后,无法返回自己的程序中,将退回到DOS状态,一般较少用到。
三、spawn类函数。此类函数功能较多,它能够由子进程返回父进程,接着运行父进程,相比之下用途
多些。
函数申明: int spawnl(int mode, char *path, char *arg0, ...)
int spawnle(int mode, char *path, char *arg0, ...)
int spawnlp(int mode, char *path, char *arg0, ...)
int spawnlpe(int mode, char *path, char *arg0, ...)
int spawnv(int mode, char *path, char *argv[])
int spawnve(int mode, char *path, char *argv[], char **env)
int spawnvp(int mode, char *path, char *argv[])
int spawnvpe(int mode, char *path, char *argv[], char **env)
函数用途: 在一个程序中调用另外一个程序
头 文 件: process.h
输入参数: path:被调用程序路径;arg:调用的参数
mode:调用模式,具体如下:
P_WAIT 0 将父过程挂起,知道子过程执行完毕
P_NOWAIT 1 父子过程同时执行,Turboc不支持
P_OVERLAY 2 子过程覆盖父过程
输出参数:
返 回 值:
使用说明: -1:调用失败,0:调用成功
*/