none
execution CommandLine from C#

    Question

  • Hi,

    I already have a Method which will execute CommandPrompt Like below

      private static int Executed(string cdName, string cdArg)
            {
                string commndArguments = cdArg;
                int exitCode;
                Process p = new Process();
                try
                {
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.FileName = cdName;
                    p.StartInfo.Arguments = commndArguments;
                    p.StartInfo.RedirectStandardError = true;
                    p.ErrorDataReceived += p_ErroraReceived;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.OutputDaReceived += p_OutputReceived;
                    p.StartInfo.CreateNoWindow = true;
                    p.Start();
    
                    p.BeginOutputReadLine();
                    p.BeginErrorReadLine();
                    p.WaitForExit();
                    exitCode = p.ExitCode;
                    p.Close();
    
                }
                catch (Exception ex)
                {
                    exitCode = 1;
                    //LogException(ex);
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
                finally
                {
                    p.Dispose();
                }
    
                return exitCode;
            }


    Now i have to Use this method and Execute the Command Line which is like below

    

    Since i have to use the above Function I am trying to write the command Like below

    string  commandnts = "/C C:\\Program Files\\Common Files\\Enterprise Single Sign-On\\ssomanage.exe -listapps /> \""  + "E:\\GIT\\Test2\\ConsoleApplication3\\ConsoleApplication3\\bin\\Debug\\DList.txt" + "\"";
             int   returnCode = ExecuteCmd("CMD.EXE", commandnts );
                Console.WriteLine(returnCode);

    But every time i get the below Error in the command Line

    C:\Program' is not recognized as an internal or external command,
    29:03:2017 16:11:16:::operable program or batch file.

    Can you Please help me with this how i can use the above function and pass these Parameters

    Thanks,

    Sujith.


    Sujith


    Wednesday, March 29, 2017 10:57 AM

Answers

  • C:\Program' is not recognized as an internal or external command,

    Use quotes around the exe file ? (
    \"C:\\Program Files\\Common Files\\Enterprise Single Sign-On\\ssomanage.exe\"

    )


    Wednesday, March 29, 2017 11:26 AM