Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Here is my code

C++
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();

    }


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
Posted
Updated 11-Mar-10 4:42am
v2

try to do the following
new ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.System)\ + @"cmd.exe", @" " + command);
 
Share this answer
 
Thanks a lot Kirill. Now the problem is solved
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900