我正在尝试使用 System.Diagnostics.Process 从 .net/c# 运行批处理文件。不知何故,它不执行批处理文件的 xcopy 命令。
示例批处理文件:
#copy test to test2 including sub directories
xcopy c:\test\ c:\test2
C#代码:
public void RunMSIBatchFile(string _workingDirectory, string batchFileName)
{
var process = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
WorkingDirectory = _workingDirectory,
FileName = _workingDirectory + batchFileName,
CreateNoWindow = true,
RedirectStandardError = true
}
};
process.OutputDataReceived += ProcessOutputDataReceived;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit(Convert.ToInt32(CommandTimeOut.TotalMilliseconds));
}
如果我将 UseShellExecute 更改为 true,那么它可以工作,但似乎无法捕获标准输出。
有没有人遇到过这样的问题?