【发布时间】:2014-02-19 18:27:35
【问题描述】:
我正在尝试在一个流程实例中运行多个命令,而我所拥有的正在运行,但它挂起并且在流写入器中的第 7 个或第 8 个命令之后什么也不做。
这是我的代码:
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd.exe";
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.CreateNoWindow = true;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
sw.WriteLine("copy /b updates\\EDB-master\\tables\\a*.sql a_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\b*.sql b_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\c*.sql c_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\d*.sql d_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\e*.sql e_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\f*.sql f_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\g*.sql g_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\i*.sql i_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\l*.sql l_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\m*.sql m_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\n*.sql n_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\o*.sql o_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\p*.sql p_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\q*.sql q_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\r*.sql r_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\s*.sql s_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\t*.sql t_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\v*.sql v_updates.sql");
sw.WriteLine("copy /b updates\\EDB-master\\tables\\w*.sql w_updates.sql");
}
p.WaitForExit();
我知道我可以将所有 SQL 文件写入一个文件,但我只使用第一个字母的原因是因为对于具有大型 sql 导入的默认 MySQL 服务器来说,它的数据包大小太大。 (程序是公开发布的,不想让每个人都编辑他们的 max_packet_size 只是为了使用该应用程序)
所以我基本上需要帮助的是弄清楚为什么它只执行部分命令,或者是否有其他方法可以做到这一点
【问题讨论】:
-
只是一个建议,您是否考虑过使用File.Copy 代替?
-
@JohnGibb,您删除的评论对我有用。在它自己的控制台应用程序中运行它。谢谢你。 (不,我没有尝试过 File.Copy,这不是我真正想走的路线)
标签: c# mysql streamwriter