How to execute a cygwin command from C# and leave it open?

Viewed 1545

I'm trying to run a cygwin command via bash from C# and try to keep the results open with the read command. My code appears to be opening the bash then immediately closing. What am I doing wrong?

static void Main(string[] args)
{
    Process bashProcess = new Process();
    bashProcess.StartInfo.FileName = @"C:\cygwin64\bin\bash.exe";
    bashProcess.StartInfo.Arguments = "-l -c echo blah; read";
    bashProcess.StartInfo.UseShellExecute = true;
    bashProcess.Start();


    bashProcess.WaitForExit();
    System.Console.WriteLine("Exit Code: {0}", bashProcess.ExitCode);

    System.Console.WriteLine("Press enter to exit...");
    System.Console.ReadLine();
}
1 Answers

Just found a solution. Enclosing the entire command with single quotes makes it work. So

bashProcess.StartInfo.Arguments = "-l -c echo blah; read";

should be replaced with the following:

bashProcess.StartInfo.Arguments = "-l -c 'echo blah; read'";
Related