Reputation: 11
I am developing a windows application.I am calling a command prompt,I need to call exe file that exe file take parameter.
I am able to open command prompt but not able to send the parametrs
string strCmdText = "create-keyfile.exe ..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Can please help me out.
Thanks
Punith
Upvotes: 0
Views: 8296
Reputation: 2459
try this.
string strCmdText = "KatanaFirmware\\key-template.txt "+ "\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
Process mp = new Process();
mp.StartInfo.FileName = "E:\\create-keyfile.exe"; //path of the exe that you want to run
mp.StartInfo.UseShellExecute = false;
mp.StartInfo.CreateNoWindow = true;
mp.StartInfo.RedirectStandardInput = true;
mp.StartInfo.RedirectStandardOutput = true;
mp.StartInfo.Arguments = strCmdText;
mp.Start();
mp.WaitForExit();
Hope it helps.
Upvotes: 0
Reputation: 30698
Have you tried cmd with /k or /c option
From the link
/c : Carries out the command specified by string and then stops.
/k : Carries out the command specified by string and continues.
string strCmdText = "/k create-keyfile.exe ..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Upvotes: 0
Reputation: 31221
ProcessStartInfo process = new ProcessStartInfo();
process.FileName = "yourprogram.exe";
process.Arguments = strCmdText; // or put your arguments here rather than the string
Process.Start(process);
Upvotes: 1
Reputation: 7705
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo("create-keyfile.exe");
startInfo.Arguments = "..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start(startInfo);
You can also see MSDN site on Process.Start, there are examples on how to execute .exe and pass arguments to it.
Upvotes: 5
Reputation: 3688
have you tried
System.Diagnostics.Process.Start("CMD.exe "+strCmdText);
Actually on further inspection I don't think you need to call CMD.EXE You should be calling your exe file, unless of course you are using CMD to to display something
string strCmdText = "..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start("create-keyfile.exe", strCmdText);
Upvotes: 0