www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - _spawnvp not support asynchronous?

#include <stdio.h>
#include <errno.h>
#include <process.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int main()
{
int pid;
const char *argv[4];
argv[0] = "cmd.exe";
argv[1] = "/Q/C";
argv[2] = "notepad";
argv[3] = 0;

pid = _spawnvp( P_NOWAIT, argv[0], argv );
if (-1 == pid) {
perror( "spawn" );
exit( -1 );
}
printf("pid = %d\n",pid);

return 0;
}



C:\ws>cl a.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

a.c
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:a.exe
a.obj

C:\ws>a.exe
pid = 2000

C:\ws>dmc a.exe
Error: no files specified

C:\ws>dmc a.c
link a,,,user32+kernel32/noi;


C:\ws>a.exe
pid = 0


dmc seems to __wait__ for the process.
MS does an asynchronous call correctly.




according to these docs, spawnvp does not support P_NOWAIT ... why should
compilation succeed???

I suppose I could use CreateProcess(), but spawnvp is cleaner and simpler.
May 05 2005