Sunday, January 31, 2016

How to Run in Cgywin from C#

Use the following code:

public  string runCygwin()
        {

            using (Process p = new Process())
            {

                /*Use the bash shell in cygwin folder*/
                ProcessStartInfo info = new ProcessStartInfo(@"D:\cygwin64\bin\bash");

                /*Put the command to be run in test.bsh*/
                info.Arguments = @"--login ""/cygdrive/D/C_Drive/Desktop/z3-str/tests.bsh""";

                /**Side Info:Content in test.bsh file**/
                string bshContent =
                    "/cygdrive/D/C_Drive/Desktop/z3-str/Z3-str.py -f " +
                    "/cygdrive/D/C_Drive/Desktop/z3-str/tests/Concat001";

                info.RedirectStandardInput = true;
                info.RedirectStandardOutput = true;
                info.UseShellExecute = false;
                p.StartInfo = info;
                p.Start();
                string output = p.StandardOutput.ReadToEnd();
                // process output
                return output;
            }
        }

No comments:

Post a Comment