3

Is there a way I can start a terminal process in C# with commands executed after it starts?

TuKsn
  • 4,330
  • 2
  • 26
  • 43
Dezmen Ceo Sykes
  • 125
  • 2
  • 2
  • 4

1 Answers1

7

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'");
        }


    }
}
TuKsn
  • 4,330
  • 2
  • 26
  • 43
  • thanks, what is "-c \ " used for? is it to ignore escape charecters, if so what are the "\" for? is it accessing commands stored as files within /bin/bash – Aboudi Mar 22 '16 at 15:39