请输入您要查询的百科知识:

 

词条 spawnl
释义

函数简介

函数名: _spawnl

所属库: process.h

功 能: 创建并且执行一个新的进程

函数原型:int _spawnl( int mode, const char *pathname, const char *arg0, const char *arg1, … const char *argn, NULL );

相关函数:_spawnle、_spawnlp、_spawnlpe、_wspawnle、_wspawnlp、_wspawnlpe、_wspawnl

程序例

程序例1

#include <process.h>

#include <stdio.h>

#include <stdlib.h>

int main(void)

{

int result;

result = spawnl(P_WAIT, "tcc.exe", NULL);

if (result == -1)

{

perror("Error from spawnl");

exit(1);

}

return 0;

}

程序例2

//这个例子中显示了8个spawn函数的用法:

#include <stdio.h>

#include <process.h>

#include <stdlib.h>

char *my_env[] = {"THIS=environment will be","PASSED=to child.exe by the","_SPAWNLE=and","_SPAWNLPE=and","_SPAWNVE=and","_SPAWNVPE=functions",NULL};

int main( int argc,char *argv[] )

{

char *args[4];

args[0] = "child";

args[1] = "spawn??";

args[2] = "two";

args[3] = NULL;

if(argc <= 2)

{

printf( "SYNTAX: SPAWN <1-8> <childprogram>\" );

exit( 1 );

}

switch (argv[1][0])

{

case '1': _spawnl( _P_WAIT, argv[2], argv[2], "_spawnl", "two", NULL );break;

case '2': _spawnle( _P_WAIT, argv[2], argv[2], "_spawnle", "two", NULL, my_env ); break;

case '3': _spawnlp(_P_WAIT, argv[2], argv[2], "_spawnlp", "two", NULL ); break;

case '4': _spawnlpe( _P_WAIT, argv[2], argv[2], "_spawnlpe", "two", NULL, my_env ); break;

case '5': _spawnv( _P_OVERLAY, argv[2], args ); break;

case '6': _spawnve( _P_OVERLAY, argv[2], args, my_env ); break;

case '7': _spawnvp( _P_OVERLAY,argv[2], args );break;

case '8': _spawnvpe( _P_OVERLAY, argv[2], args, my_env ); break;

default: printf( "SYNTAX: SPAWN <1-8> <childprogram>\" );exit( 1 );

}

printf( "from SPAWN!\" );

return 0;

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/12/23 18:58:44