-1

i'm trying to create a process using the following code:

void GenerateCommandLine( char *commandLine, 
                          int maxLength, 
                          const char *imageTitle) {
    const char * COMMAND_LINE_TEMPLATE = "AnalyzeImage.exe --image_file %s";
    sprintf_s(  commandLine, 
                maxLength, 
                COMMAND_LINE_TEMPLATE, 
                imageTitle 
    );
}

int AnalyzeCurrentImage(char* imageTitle) {
    STARTUPINFO         startupInfo;
    PROCESS_INFORMATION processInfo;
    DWORD               exitCode = MAXINT;
    char                commandLine[ MAX_ELEMENT_LENGTH ];

    commandLine[ 0 ] = '\0';
    InitVariables( &startupInfo, &processInfo );
    GenerateCommandLine( commandLine, MAX_ELEMENT_LENGTH, imageTitle );
    printf( "-----------command line is: %s\n", commandLine );


    // Start the AnalyzeImage process. 
    if( !CreateProcess( NULL,       // No module name (use command line)
        commandLine,                // 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 
        &startupInfo,   // Pointer to STARTUPINFO structure
        &processInfo )  // Pointer to PROCESS_INFORMATION structure
    ) 
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return;
    }
    printf("here!!!");
    // Wait until AnalyzeImage process exits.
    WaitForSingleObject( processInfo.hProcess, INFINITE );

    GetExitCodeProcess( processInfo.hProcess, &exitCode );
    printf( "------------ Exit Code: %d\n", exitCode );

    // Close process and thread handles. 
    CloseHandle( processInfo.hProcess );
    CloseHandle( processInfo.hThread );
}

when i run this program from the command line i get the following:

"-------command line is: AnalyzwImage.exe --imgage_file img000.jpg CreateProess failed <2>"

do you have and idea why the create process is failing?

thank you

2 Answers2

0

Error code 2 is File Not Found so CreateProcess is unable to find AnalzwImage.exe. It is either not in the current directory or in the system path. Try using the full path to AnalzwImage.exe.

shf301
  • 31,086
  • 2
  • 52
  • 86
0

The code 2 returned by GetLastError() means ERROR_FILE_NOT_FOUND.

Simply put, AnalyzwImage.exe could not be found. You should either include the absolute path to the executable in the command line, or make sure that the current working directory at the time CreateProcess is called is the directory where AnalyzwImage.exe is located.