I've already tried system() and spawnl, but strangely, the .exe program that I've tried to execute within my C++ program didn't work as it should be.
this is my piece of code:
#include <stdio.h>
#include开发者_如何学编程 <process.h>
int main(void)
{
puts("Executing simpleTest.exe....");
spawnl( P_WAIT, "C:/simpleTest.exe",
"C:/simpleTest.exe", "Using spawnl", "Arg1", "Arg2", NULL );
system("pause");
return 0;
}
that simpleTest.exe is actually a C++ console application too, and I want to invoke it within a C++ console application named Invoke.exe....I wonder if that's what my problem is. If I execute simpleTest.exe by double-clicking it, it works fine....but if I execute it with above code, it exits because it encounters an error... I wonder where did I do wrong? Is there any other suggestion beside above code? Oh yeah, I'm using Microsoft Visual Studio 2008 by the way... Any help will be appreciated, thanks.
The MSVC (Windows actually) way to execute a process is via CreateProcess function. I've never used spawnl however, so I don't know how it works.
Using native C runtime process-creation functions would eventually call CreateProcess
only. They may also create a console window, which may not be desirable.
Therefore, it is recommended to use CreateProcess
or ShellExecute
family of functions.
精彩评论