c++ - 使用具有相对路径的 CreateProcess

标签 c++ windows process winapi

是否可以通过相对路径来创建我的子进程? 这段代码可以编译,但会报错,因为我使用的是相对路径。

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


}

最佳答案

一些事情:

  1. 正如@Oswald 所说,\ 是当前驱动器的根文件夹,而不是相对路径。
  2. 你忘了转义你的反斜杠。你真的想要 TEXT("..\\Debug\\traitement.exe")

关于c++ - 使用具有相对路径的 CreateProcess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486350/

相关文章:

linux kill命令-9 vs -15

apache - 无法分配内存 : fork: Unable to fork new process : server apache, 如何找到源并修复它?

android - 在Android Studio Project中使用Tensorflow Lite C++ API的问题

c# - 为什么复制到U盘时文件修改时间自动增加2秒?

C++ - 在后台 POSIX 线程上以固定增量时间循环

windows - 如何填充页面并根据调整大小调整文本位置

c - 使用 winHttpApi 或套接字发送大文件是否明智?

c# - 在 C# 中杀死 python 脚本

c++ - 如何获取 insertRows 源?

c++ - 如何在 x86(Pentium 及更高版本)上执行原子 64b 读取?