Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have two strings
C#
string OrginalCreateTransformMsi = "D:\\Desktop\\Jonty-transform creator\\MSITransformTool.exe";
string strMSIName = "D:\\Desktop\\SetUps\\Orca.Msi";

I want to run this through command prompt
C#
private void ExecuteCommandLine(string strCMDText)
{
    //System.Diagnostics.Process.Start("CMD.exe", strCmdText);
    string tempGETCMD = null;
    Process CMDprocess = new Process();
    ProcessStartInfo StartInfo = new ProcessStartInfo();
    StartInfo.FileName = "cmd"; //starts cmd window
    //StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    StartInfo.CreateNoWindow = true;
    StartInfo.RedirectStandardInput = true;
    StartInfo.RedirectStandardOutput = true;
    StartInfo.UseShellExecute = false; //required to redirect
    CMDprocess.StartInfo = StartInfo;
    CMDprocess.Start();
    StreamReader SR = CMDprocess.StandardOutput;
    StreamWriter SW = CMDprocess.StandardInput;
    SW.WriteLine("@echo on");
    SW.WriteLine(strCMDText); //the command you wish to run.....
    //SW.WriteLine("cd C:\\Program Files");
    //insert your other commands here
    SW.WriteLine("exit"); //exits command prompt window
    tempGETCMD = SR.ReadToEnd(); //returns results of the command window
    SW.Close();
    SR.Close();
}

ExecuteCommandLine(OrginalCreateTransformMsi +" " + strMSIName);

i need to add an extra " between first string OrginalCreateTransformMsi ,
do do we have any other methods ?

Please assist
Posted
Updated 5-May-15 5:08am
v2
Comments
Tomas Takac 5-May-15 11:12am    
Why all that code? What's wrong with Process.Start(OrginalCreateTransformMsi, strMSIName)[^]?
Sergey Alexandrovich Kryukov 5-May-15 11:14am    
Will you post it as an answer?
—SA
Tomas Takac 5-May-15 11:35am    
You are right, it's just seemed too simple. :)

1 solution

You can execute the command simply by calling Process.Start()[^]:
C#
Process.Start(OrginalCreateTransformMsi, strMSIName);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-May-15 11:47am    
Sure, a 5.
—SA

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