CreateProcess() c++ file not found

docaholic

I'm trying to use CreateProcess to start a child process, however I keep getting error 2, which, according to the documentation is file not found.

My code looks like this:

if (!(CreateProcess(LPCTSTR("test.exe") ,NULL ,NULL,NULL,FALSE ,0  ,NULL ,NULL ,&producer_si
              ,&producer)))
{
    printf("Create process failed!(%d)\n", GetLastError());
}

Where test.exe is an executable program which I created earlier. The child process is very simple, with the code looking like this:

void _tmain (int argc, TCHAR* argv[])
{
printf("%s\n", "hello!"); 
} 

test.exe is also found in the same folder as the parent process. I'm not understanding why I'm always getting an error code of 2.

Remy Lebeau

Error 2 is ERROR_FILE_NOT_FOUND. As others have told you, you are relying on a relative path when you need to use an absolute path instead.

Also, LPCTSTR("test.exe") is not valid code. If UNICODE is defined, CreateFile() maps to CreateFileW(), and LPCTSTR maps to LPCWSTR ie const wchar_t*. You cannot typecast a char* to a wchar_t* and end up with meaningful data. If you want to use TCHAR-sensitive literals, use the TEXT() macro instead, eg:

if (!CreateProcess(TEXT("full path to\\test.exe"), ...))

Otherwise, forget using TCHAR and just write Ansi-specific or Unicode-specific code instead, depending on your needs:

if (!CreateProcessA("full path to\\test.exe", ...))

if (!CreateProcessW(L"full path to\\test.exe", ...))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CreateProcess() c++ file not found

From Dev

C++ CreateProcess error-code 2 ("ERROR_FILE_NOT_FOUND") on Windows 7 (64)

From Dev

Objective C on Windows - Error - CreateProcess: No such file or directory

From Dev

SetWinEventHook with CreateProcess, C++

From Dev

C file never found

From Dev

C file never found

From Dev

C++ CreateProcess - System Error #2 can't find file - what is wrong with my file path?

From Dev

Use CreateProcess to Run a Batch File

From Dev

NetBeans + MinGW + C - file not found

From Dev

AppStartError: CreateProcess: The system cannot find the file specified

From Dev

Getting errors with CreateProcess in C using putenv and getpid

From Dev

Starting Speech Recognition with CreateProcess() in C++

From Dev

How to call CreateProcess() in C# passing lpEnvironment

From Dev

C++ - CreateProcess failed code 2

From Dev

C - If (No File Found) { Use standard input }

From Dev

C++ read file until char found

From Dev

C++ command line args (file) not found?

From Dev

C: Symbols not found for function defined in file?

From Dev

C# File.Copy Directory Not Found

From Dev

CreateProcess error=2, The system cannot find the file specified [Android studio]

From Dev

CreateProcess error=2, The system cannot find the file specified

From Dev

C++ WinApi CreateProcess Unable To Create Child Process With Environment Block

From Dev

CreateProcess: redirect child stdout to parent stdout in C++/Windows

From Dev

C++ WinApi CreateProcess Unable To Create Child Process With Environment Block

From Dev

Unable to locate a number found in a text file c#

From Dev

Error "The specified file was not found" when compiling c++ on notepad++

From Dev

Segmentation fault when file is not found even if I try to create it in C

From Dev

How to create exception for database file not found in c#

From Dev

objective-c use cocoapods add Swift framework not found file

Related Related

  1. 1

    CreateProcess() c++ file not found

  2. 2

    C++ CreateProcess error-code 2 ("ERROR_FILE_NOT_FOUND") on Windows 7 (64)

  3. 3

    Objective C on Windows - Error - CreateProcess: No such file or directory

  4. 4

    SetWinEventHook with CreateProcess, C++

  5. 5

    C file never found

  6. 6

    C file never found

  7. 7

    C++ CreateProcess - System Error #2 can't find file - what is wrong with my file path?

  8. 8

    Use CreateProcess to Run a Batch File

  9. 9

    NetBeans + MinGW + C - file not found

  10. 10

    AppStartError: CreateProcess: The system cannot find the file specified

  11. 11

    Getting errors with CreateProcess in C using putenv and getpid

  12. 12

    Starting Speech Recognition with CreateProcess() in C++

  13. 13

    How to call CreateProcess() in C# passing lpEnvironment

  14. 14

    C++ - CreateProcess failed code 2

  15. 15

    C - If (No File Found) { Use standard input }

  16. 16

    C++ read file until char found

  17. 17

    C++ command line args (file) not found?

  18. 18

    C: Symbols not found for function defined in file?

  19. 19

    C# File.Copy Directory Not Found

  20. 20

    CreateProcess error=2, The system cannot find the file specified [Android studio]

  21. 21

    CreateProcess error=2, The system cannot find the file specified

  22. 22

    C++ WinApi CreateProcess Unable To Create Child Process With Environment Block

  23. 23

    CreateProcess: redirect child stdout to parent stdout in C++/Windows

  24. 24

    C++ WinApi CreateProcess Unable To Create Child Process With Environment Block

  25. 25

    Unable to locate a number found in a text file c#

  26. 26

    Error "The specified file was not found" when compiling c++ on notepad++

  27. 27

    Segmentation fault when file is not found even if I try to create it in C

  28. 28

    How to create exception for database file not found in c#

  29. 29

    objective-c use cocoapods add Swift framework not found file

HotTag

Archive