Dezmen Ceo Sykes Asked: 2014-08-05 20:07:18 +0800 CST2014-08-05 20:07:18 +0800 CST 2014-08-05 20:07:18 +0800 CST c# - Opening the terminal process and pass commands? 772 Is there a way I can start a terminal process in C# with commands executed after it starts? gnome-terminal 1 Answers Voted Best Answer TuKsn 2014-08-06T00:52:27+08:002014-08-06T00:52:27+08:00 Try this: using System; using System.Diagnostics; namespace runGnomeTerminal { class MainClass { public static void ExecuteCommand(string command) { Process proc = new System.Diagnostics.Process (); proc.StartInfo.FileName = "/bin/bash"; proc.StartInfo.Arguments = "-c \" " + command + " \""; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start (); while (!proc.StandardOutput.EndOfStream) { Console.WriteLine (proc.StandardOutput.ReadLine ()); } } public static void Main (string[] args) { ExecuteCommand("gnome-terminal -x bash -ic 'cd $HOME; ls; bash'"); } } }
Try this: