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条回答

    报告相同问题?

    悬赏问题

    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条