111,082
社区成员




string command = "dir";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
// string strOutput = null;
try
{
p.Start();
Console.WriteLine("command:" + command);
p.StandardInput.WriteLine(command + "&exit");
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
Console.WriteLine("result:" + output);
}
catch (Exception e1)
{
Console.WriteLine("error" + e1.Message);
}
p.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe /k cd /d"+" \"D:\\ServKit\"";//后面的 \"D:\\ServKit\"替换为你需要的路径即可。
能看明白吗?
p.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe /k cd /d \"D:\\ServKit\"";//后面的 \"D:\\ServKit\"替换为你需要的路径即可。
C:\Windows\System32\cmd.exe /k cd /d "D:\ServKit"