RT
网上找了很多资料,都没有成功 下面是代码
private void button1_Click(object sender, EventArgs e)
{
startcmd("cmd.exe", "shutdown -r -t 800");
}
public static void startcmd(string command, string argument)
{
Process cmd = new Process();
cmd.StartInfo.FileName = command;
cmd.StartInfo.Arguments = argument;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start();
}
为什么我点了按钮一点反应都没有?
自己做出来了 哎 自学痛苦啊
private void button1_Click(object sender, EventArgs e)
{
startcmd("cmd.exe", "echo 1234>d:\\1.txt");
}
public static void startcmd(string command, string argument)
{
Process cmd = new Process();
cmd.StartInfo.FileName = command;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start();
cmd.StandardInput.WriteLine(argument);
cmd.StandardInput.WriteLine("exit");
string ss = cmd.StandardOutput.ReadToEnd();
cmd.WaitForExit();
cmd.Close();
}
请问同时执行多个命令 要如何写?
追答多个命令写到 批处理去
然后执行批处理即可。
当然 一条一条执行也可。。