2010-12-20 226 views
2

是否可以传递一个相对路径来创建我的子进程? 此代码将进行编译,但由于使用相对路径,因此会出现错误。使用CreateProcess和相对路径

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(); 


} 

回答

5

两件事情:

  1. 作为@Oswald说,\是当前驱动器的根文件夹,而不是相对路径。
  2. 你忘了逃避你的反斜杠。你真的想要TEXT("..\\Debug\\traitement.exe")
+0

由于某种原因,今天它的工作。我已经放弃了子进程,并且正在使用Visual Studio来启动这两个项目。非常感谢! – toto 2010-12-21 15:39:25

5

它看起来不像我的相对路径。 \是当前驱动器的根文件夹。

+0

谢谢,我不知道。 – toto 2010-12-21 15:39:48