是否可以通过相对路径来创建我的子进程? 这段代码可以编译,但会报错,因为我使用的是相对路径。
void Cminivideo3App::creerChildProcess(void)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
int retvalue = CreateProcess( TEXT("\..\Debug\traitement.exe"), // No module name (use command line)
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure
);
int lastError = GetLastError();
}
最佳答案
一些事情:
- 正如@Oswald 所说,
\
是当前驱动器的根文件夹,而不是相对路径。 - 你忘了转义你的反斜杠。你真的想要
TEXT("..\\Debug\\traitement.exe")
。
关于c++ - 使用具有相对路径的 CreateProcess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486350/