2

my program is running well all the time but it suddenly stuck at Process.WaitForExit(); without proceeding to the next command. I have already ran the program multiple time without having error. Is anyone one know how can I debug this or is anyone know what is the problem behind? Could it be problem with my python.exe? Thanks!

public static void Process(string location)
    {
        int ExitCode;
        ProcessStartInfo ProcessInfo;
        Process Process;

        ProcessInfo = new ProcessStartInfo();
        ProcessInfo.FileName = location;
        ProcessInfo.Arguments = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + 
            "\\parse.py " + Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\cache.cell";
        ProcessInfo.CreateNoWindow = true;
        ProcessInfo.UseShellExecute = false;
        ProcessInfo.RedirectStandardOutput = true;
        ProcessInfo.RedirectStandardError = true;
        Process = Process.Start(ProcessInfo);
        // (...)
        Process.WaitForExit();

        string stderr = Process.StandardError.ReadToEnd();
        string stdout = Process.StandardOutput.ReadToEnd();
        //Console.WriteLine("STDERR: " + stderr);
        //Console.WriteLine("STDOUT: " + stdout);

        using (System.IO.StreamWriter file = new System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.txt"))
        {
            file.WriteLine(stdout);
        }
4

1 に答える 1

1

プロセスが終了するまで、プログラムは何も出力しません。プロセスが終了しない場合、何も表示されず、問題をデバッグすることはできません。

途中で印刷した方がいい

var info = new ProcessStartInfo("msbuild")
{
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardError = true,
    RedirectStandardOutput = true,            
};

using (var p = Process.Start(info) )
{
    p.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data);
    p.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
    p.BeginErrorReadLine();
    p.BeginOutputReadLine();
    p.WaitForExit();
}

msbuild 出力から色を保持する方法を参照してください。

于 2013-07-16T10:58:07.917 に答える