0

私はc#でdotnetを介してbatファイルを実行しました以下のとおりです

Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "d://s.bat";
                p.Start();
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();

dotnetideを実行している間は正常に動作します。

しかし、私の問題は、IISを介して公開した後に上記のコードを実行すると、次のようなエラーが返されることです。

StandardOut-has-not-been-redirected-or-the-process-hasn-t-started-yet。

この問題を解決するためのガイドラインを教えてください。

4

2 に答える 2

1

を使用する必要がありRedirectStandardOutput = trueます。MSDNからのリンク

リンクから引用:

ProcessStartInfo.RedirectStandardOutput プロパティ アプリケーションの出力が Process.StandardOutput ストリームに書き込まれるかどうかを示す値を取得または設定します。

サーバーが起動していることを確認していたときの、私の問題から同じ問題へのスニペット。

if (IsProcessRunning(ServerProcessName)) { return; }
        var p = new Process
        {
            StartInfo = new ProcessStartInfo
                            {
                                FileName = path,
                                RedirectStandardOutput = true, 
                                UseShellExecute = false
                            }
        };
        p.Start();
        var a = "";
        while (!a.Contains("ServicesStarted"))
        {
            a = p.StandardOutput.ReadLine();
        }
于 2012-08-22T06:40:45.793 に答える
1

エラーを克服するには、次のようにします。

StringBuilder content = new StringBuilder();
while ( ! p.HasExited ) {
    content.Append(p.StandardOutput.ReadToEnd());
}
string output = content.ToString();
于 2012-08-22T06:40:45.917 に答える