i have exe file generated by the Compilation of C++ program now I want to pass arguments to the generated exe file through C# and save all of the output of exe file on a .txt file this is What i have done so far
public static string RunCmd(params int[] commands)
{
string returnvalue = string.Empty;
ProcessStartInfo info = new ProcessStartInfo("C:\\...\\.exe");
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
using (Process process = Process.Start(info))
{
StreamWriter sw = process.StandardInput;
StreamReader sr = process.StandardOutput;
//foreach (int command in commands)
//{
// sw.WriteLine(command);
//}
for (int i = 0; i < commands.Length; i++)
{
sw.WriteLine(commands[i]);
}
sw.Close();
returnvalue = sr.ReadToEnd();
process.Close();
System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\..\\.txt");
file.WriteLine(returnvalue);
file.Close();
return returnvalue;
}
it work well for a single argument but whenever i try to enter multiple Arguments,it just opens the .exe file and not work further