本文介绍了如何使用c#desctop应用程序运行和更改命令提示符路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
Hi Here is my code
public void ExecuteCommand(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
ProcessStartInfo procStartInfo =
new ProcessStartInfo(@"cmd.exe", @" " + command);
//ProcessStartInfo procStartInfo = new ProcessStartInfo();
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
//procStartInfo.FileName = "notepad.exe";
// Now we create a process, assign its ProcessStartInfo and start it
Process proc = Process.Start(procStartInfo);
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
MessageBox.Show(result);
objClsLog.WriteToLog(result, null);
// Close the process
proc.WaitForExit();
}
它通过默认将cmd路径作为项目bin/debug路径,我需要更改此cmd运行路径.是否有可能使用C#代码更改cmd路径.在此先感谢
it takes cmd path as project bin/debug path by defualt i need to change this cmd running path. Is there any possibility to change the cmd path using c# code. Thanks in advance
推荐答案
new ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.System)\ + @"cmd.exe", @" " + command);
这篇关于如何使用c#desctop应用程序运行和更改命令提示符路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!