Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1758952
  • 博文数量: 290
  • 博客积分: 10653
  • 博客等级: 上将
  • 技术积分: 3178
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-24 23:08
文章存档

2013年(6)

2012年(15)

2011年(25)

2010年(86)

2009年(52)

2008年(66)

2007年(40)

分类: C/C++

2009-07-02 15:21:38

Create and execute a new process.


intptr_t _spawnvpe(
int mode,
const char *cmdname,
const char *const *argv,
const char *const *envp
);
intptr_t _wspawnvpe(
int mode,
const wchar_t *cmdname,
const wchar_t *const *argv,
const wchar_t *const *envp
);

Parameters

mode

Execution mode for calling process

cmdname

Path of file to be executed

argv

Array of pointers to arguments

envp

Array of pointers to environment settings


// crt_spawn.c

// This program accepts a number in the range

// 1-8 from the command line. Based on the number it receives,

// it executes one of the eight different procedures that

// spawn the process named child. For some of these procedures,

// the CHILD.EXE file must be in the same directory; for

// others, it only has to be in the same path.

//


#include <stdio.h>
#include <process.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];

   // Set up parameters to be sent:

   args[0] = "child";
   args[1] = "spawn??";
   args[2] = "two";
   args[3] = NULL;

   if (argc <= 2)
   {
      printf( "SYNTAX: SPAWN <1-8> \n" );
      exit( 1 );
   }

   switch (argv[1][0]) // Based on first letter of argument

   {
   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> \n" );
      exit( 1 );
   }
   printf( "from SPAWN!\n" );
}

阅读(1616) | 评论(0) | 转发(0) |
0

上一篇:system

下一篇:Staring a Service

给主人留下些什么吧!~~