D:\wamp\bin\mysql\mysql5.1.36\bin\mysqldump.exe --opt -R -u root -pvaodesql_2011 k801>"D:/wamp/vaode_mysql_backup/k801_mysql_backup当前年月日分秒.sql;

需求如下:0,6,12,18,定点备份数据库,执行dos命令!

推荐图书

  • C#与.NET 4高级程序设计(第5版)


1个回答

private   void   button1_Click(object   sender,   EventArgs   e)
{
        Process   myProcess   =   new   Process();
        myProcess.StartInfo.FileName   =   "cmd.exe ";//DOS控制平台
        myProcess.StartInfo.UseShellExecute   =   false;
        myProcess.StartInfo.CreateNoWindow   =   true;
        myProcess.StartInfo.RedirectStandardInput   =   true;
        myProcess.StartInfo.RedirectStandardOutput   =   true;
        myProcess.StartInfo.RedirectStandardError   =   true;
        myProcess.Start();
        StreamWriter   sIn   =   myProcess.StandardInput;//标准输入流
        sIn.AutoFlush   =   true;
        StreamReader   sOut   =   myProcess.StandardOutput;//标准输入流
        StreamReader   sErr   =   myProcess.StandardError;//标准错误流
        sIn.Write( "ver "   +   System.Environment.NewLine);//DOS控制平台上的命令
        sIn.Write( "dir "   +   System.Environment.NewLine);//DOS控制平台上的命令
        sIn.Write( "exit "   +   System.Environment.NewLine);
        string   s   =   sOut.ReadToEnd();//读取执行DOS命令后输出信息
        string   er   =   sErr.ReadToEnd();//读取执行DOS命令后错误信息
        richTextBox1.AppendText(s);
        richTextBox1.AppendText(er);
        if   (myProcess.HasExited   ==   false)
        {
                myProcess.Kill();
        }
        sIn.Close();
        sOut.Close();
        sErr.Close();
        myProcess.Close();
}