6

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?

2
  • 1
    I'm assuming that the .net program is running in mono on linux. Right? Commented Dec 24, 2013 at 16:38
  • @corey, op wants any api for executing unix shell script in.net?? Commented Dec 24, 2013 at 16:42

2 Answers 2

8

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
}
Sign up to request clarification or add additional context in comments.

2 Comments

This works fine for windows files. Will this work for linux files?
actually i did not check this on linux ... but in windows it works fine
0
        ProcessStartInfo frCreationInf = new ProcessStartInfo();
        frCreationInf.FileName = @"C:\Program Files\Git\git-bash.exe";
        frCreationInf.Arguments = "Test.sh";
        frCreationInf.UseShellExecute = false;
        var process = new Process(); 
        process.StartInfo = frCreationInf;
        process.Start();
        process.WaitForExit();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.