Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a shell script in C#?

Tags:

c#

.net

I have one file which contains a Unix shell script. So now I wanted to run the same in .NET. But I am unable to execute the same.

So my point is, is it possible to run the Unix program in .NET? Is there any API like NSTask in Objective-C for running Unix shell scripts so any similar API in .NET?

like image 878
Abdeali Siyawala Avatar asked Dec 24 '13 16:12

Abdeali Siyawala


1 Answers

It has been answered before. Just check this out.

By the way, you can use:

Process proc = new Process {
    StartInfo = new ProcessStartInfo {
        FileName = "program.exe",
        Arguments = "command line arguments to your executable",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    }
};

After that start the process and read from it:

proc.Start();
while (!proc.StandardOutput.EndOfStream) {
    string line = proc.StandardOutput.ReadLine();
    // Do something with line
}
like image 187
Pouya Samie Avatar answered Oct 04 '22 15:10

Pouya Samie