Probleme mit CreateProcess => 'System.AccessViolationException'



  • Hallo!

    Ich will ein Programm aufrufen und danach warten bis es erfolgreich beendet wurde und danach den Output in einen Text datei umleiten um verschiedene ergebnisse auszuwerten.

    Zur Zeit beschränke ich mich auf den Programmaufruf.

    mit

    help=WinExec("demo.bat", SW_NORMAL);
    

    funktioniert das wunderbar, aber damit kann ich nicht überprüfen ob das Programm noch läuft. Also CreateProzess (aus Hilfe Datei kopiert und bearbeitet)

    STARTUPINFO si;
        PROCESS_INFORMATION pi;
    
        ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );
    
        // Start the child process. 
        if( !CreateProcess( NULL,   // No module name (use command line). 
            TEXT("demo.bat"), // 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.
        ) 
        {
            printf( "CreateProcess failed (%d).\n", GetLastError() );
            return;
        }
    
        // Wait until child process exits.
        WaitForSingleObject( pi.hProcess, INFINITE );
    
        // Close process and thread handles. 
        CloseHandle( pi.hProcess );
        CloseHandle( pi.hThread );
    

    Leider tritt hier eine Fehlermeldung auf:
    "An unhandled exception of type 'System.AccessViolationException' occurred in test.exe

    Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    Weiß jemand rat?

    lg



  • Hallo

    Habe mein Programmaufruf-Problem gelöst. Man muss

    wchar_t runit[] = L"demo.bat";
    

    oben einfügen und als 2. Parameter bei CreateProcess übergeben.

    Irgend ein internes windows Problem erlaubt nur diesen aufruf wenn ichs richtig verstanden habe.

    mfg


  • Mod

    Und was sagt der Debugger?

    "System.AccessViolationException" hört sich schwer nach C++/CLI an?



  • Aber ganz schwer.... dann also lieber System::Diagnostics::Process::Start verwenden...



  • Dieser Thread wurde von Moderator/in Martin Richter aus dem Forum MFC (Visual C++) in das Forum C++/CLI mit .NET verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.


Anmelden zum Antworten