我对 bat 文件中的 windows shell find 命令有问题。find 命令的输出始终为空。Bat 文件Process.Start
在 C# 中使用 .NET 的方法执行。我使用输出流重定向。我想做的事:
ProcessStartInfo processInfo = new ProcessStartInfo("c:\test.bat")
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
Process testProcess = new Process();
testProcess.EnableRaisingEvents = true;
testProcess.OutputDataReceived += new DataReceivedEventHandler(testProcess_OutputDataReceived);
testProcess.ErrorDataReceived += new DataReceivedEventHandler(testProcess_ErrorDataReceived);
testProcess.StartInfo = processInfo;
testProcess.Start();
批处理文件 (c:\test.bat) 包含带有重定向到输出文件的 find 命令:
find /I "TestString" "c:\TestInput.xml" > output.txt
outputStream 的重定向工作正常,但 output.txt 的内容为空(文件大小为 0B)。当我执行相同的批处理命令时, output.txt 包含找到的字符串出现。是否可以在批处理文件中使用 find 命令Process.Start
并重定向输出流?
谢谢你的帮助。