gpt4 book ai didi

C# - 进程没有终止

转载 作者:太空宇宙 更新时间:2023-11-03 19:35:17 24 4
gpt4 key购买 nike

我正在恢复 MySql 中的备份。但是 mysql exe 没有终止。这是我的代码 -

public override bool FullRestore(Stream fileStream)
{
try
{
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format("--database {0} --user={1} --password={2}", config.GetDbName(), config.GetUserName(), config.GetPassword());
proc.FileName = "mysql";
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
proc.CreateNoWindow = true;
Process p = Process.Start(proc);
Stream stream = p.StandardInput.BaseStream;
Stream file = Utility.ZipNEncrypt.Unzip(fileStream, "XXXXXX");
byte[] bytes = new byte[1024];
for (int count = 0; (count = file.Read(bytes, 0, 1024)) > 0; )
{
stream.Write(bytes, 0, count);
}
stream.Flush();
p.WaitForExit();
file.Close();
return true;
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.ToString());
return false;
}
}

我的 BackUp 方法运行良好,但此方法无效。(它们非常相似)

有什么建议吗?

最佳答案

您需要关闭 StandardInput 流:

stream.Close();
p.WaitForExit();

否则,程序不会终止,因为它需要更多的输入。

关于C# - 进程没有终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2038996/

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