Arthurlichen 2014-01-23 19:58
浏览 2515

C#winform项目制作安装包想把mysql数据库一起附加进去,调用cmd执行脚本无效,求助

                string dbname = this.Context.Parameters["dbname"];//数据库名称
                string server = this.Context.Parameters["server"];//服务器名称
                string uid = this.Context.Parameters["user"];//SQlServer用户名
                string pwd = this.Context.Parameters["pwd"];//密码
                string path = this.Context.Parameters["targetdir"];//安装目录
                String appDirecroty = "C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin\\";
                StringBuilder sbcommand = new StringBuilder();
                string directory = path + "database" + "\\" + "121www.sql";
                sbcommand.AppendFormat("mysql -uroot -p123456 121www < {0}", directory);
                String command = sbcommand.ToString();
                //MessageBox.Show(command);
                Cmd.StartCmd(appDirecroty, command);

Cmd中是这样写的
public class Cmd
{
///
/// 执行Cmd命令
///
/// 要启动的进程的目录
/// 要执行的命令
public static void StartCmd(String workingDirectory, String command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//MessageBox.Show(p.StartInfo.WorkingDirectory);
p.StartInfo.WorkingDirectory = workingDirectory;
//MessageBox.Show(p.StartInfo.WorkingDirectory);
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(command);
//MessageBox.Show(command);
p.StandardInput.WriteLine("exit");
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
    • ¥88 实在没有想法,需要个思路
    • ¥15 MATLAB报错输入参数太多
    • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
    • ¥15 有赏,i卡绘世画不出