2016-07-11 11 views
0

Ich arbeite an ILOG, das von IBM entwickelt wurde. ILOG Programm kann über cmd Konsole ausgeführt werden, wie folgt:C# externer Programmaufruf Verzeichnisfehler

oplrun -p C:\Users\pc_copat\opl\santez\"workName"

Wenn ich diesen Code oben schreiben Konsolenbildschirm cmd, wird das Programm ohne Fehler arbeiten. Obwohl ich diese Codes in C# wie folgt verwendete, funktioniert es nicht.

`string komut = @"oplrun -p C:\Users\pc_copat\opl\santez\ " + '\u0022' + calismaAdi + '\u0022';` 

     ProcessStartInfo startInfo = new ProcessStartInfo(); 
     //startInfo.CreateNoWindow = false; 
     startInfo.UseShellExecute = false; 
     startInfo.FileName = "cmd.exe"; 
     startInfo.WindowStyle = ProcessWindowStyle.Hidden; 
     startInfo.Arguments = "/K "+komut; 

     try 
     { 
      // Start the process with the info we specified. 
      // Call WaitForExit and then the using-statement will close. 
      using (Process exeProcess = Process.Start(startInfo)) 
      { 
       exeProcess.WaitForExit(); 
      } 
     } 
     catch 
     { 
      // Log error. 
     } 

ich immer diese Fehlermeldung erhalten:

'oplrun' is not recognized as an internal or external command, operable program or batch file.

Wie kann ich dieses Problem beheben?

+0

Versuchen Sie den vollständigen Dateipfad für oplrun.exe in Ihrem Code verwenden, anstatt nur den Befehl. Wenn das funktioniert, überprüfen Sie die Umgebungsvariable PATH Ihres Systems, um sicherzustellen, dass das System weiß, wo es oplrun finden kann. –

+0

Ist dieser Pfad korrekt? 'C: \ Benutzer \ pc_copat \ opl \ santez \" + '\ u0022' + calismaAdi + '\ u0022'', sehe ich mehrere Schrägstriche und ein paar zusätzliche Anführungszeichen? – Hexie

Antwort

-1

Statt Gabe von Parametern können Sie StandardInput.WriteLine verwenden, um Befehle auf cmd ausführen ...

string komut = @"oplrun -p C:\Users\pc_copat\opl\santez\ " + '\u0022' + calismaAdi + '\u0022'; 

    ProcessStartInfo startInfo = new ProcessStartInfo(); 
    //startInfo.CreateNoWindow = false; 
    startInfo.UseShellExecute = false; 
    startInfo.FileName = "cmd.exe"; 
    startInfo.WindowStyle = ProcessWindowStyle.Hidden; 
    //startInfo.Arguments = "/K "+komut; 
    startInfo.RedirectStandardOutput = true; 
    startInfo.RedirectStandardInput = true; 
    string currentFolderString = AppDomain.CurrentDomain.BaseDirectory; // Not sure if this will work but it should be your directory containing the oplrun.exe 
    try 
    { 
     // Start the process with the info we specified. 
     // Call WaitForExit and then the using-statement will close. 
     using (Process exeProcess = Process.Start(startInfo)) 
     { 
      exeProcess.StandardInput.WriteLine(string.format("cd \"{0}\"", currentFolderString)); // navigate to the oplrun.exe directory 
      exeProcess.StandardInput.WriteLine(komut); // execute komut instead of as param 
      exeProcess.WaitForExit(); 
     } 
    } 
    catch 
    { 
     // Log error. 
    }