gpt4 book ai didi

c# - 从 C# 运行时,Xcopy 不复制文件

转载 作者:行者123 更新时间:2023-11-30 14:50:53 25 4
gpt4 key购买 nike

我从 C# 代码启动 .bat 文件:

     void ExecuteCommand(string command)
{
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;

var process = Process.Start(processInfo);

process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("output>>" + e.Data);
process.BeginOutputReadLine();

process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("error>>" + e.Data);
process.BeginErrorReadLine();

process.WaitForExit();

Console.WriteLine("ExitCode: {0}", process.ExitCode);
process.Close();
}

它开始了,一切都被执行了,但是:

set mydir = "C:\mydir"
xcopy /c /y "myFile.exe" %mydir%

文件没有被复制

但是当我从资源管理器运行同一个批处理文件时,文件被复制了。有什么想法吗?

最佳答案

添加 processInfo.RedirectStandardInput = true;为我工作 - 现在文件复制没有问题

关于c# - 从 C# 运行时,Xcopy 不复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35703908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com