6

In my current project, i need to call a Unix shell script from the C# application. I also need to get the response back whether the script has been execute successfully or any error has occurred.

The C# program is running on a Windows machine. I need to connect to a Unix machine and execute the script.

Can anyone let me know how this can be done using C#?

2
  • Are you running the C# program on the Unix box? Commented Jun 2, 2011 at 15:33
  • C# program is in windows machine. I need to connect to unix machine and execute the script. Commented Jun 3, 2011 at 4:39

3 Answers 3

4

Will this solve your problem?

sharpSsh - A Secure Shell (SSH) library for .NET

Update

Refer to the developer's site for SharpSSH for more information on how to use the tool.

Update 2

  • change link of developer site to archived link.
Sign up to request clarification or add additional context in comments.

5 Comments

I have checked this. This seems to be promising. But as the author mentioned its not complete. We are getting error when connecting to remote machine. We are trying to solve this out.
Hi, We tried out, but unable to solve the issue. We are getting timed out error when connecting to remote machine.
Hi, We tried out, but unable to solve the issue. We are getting timed out error when connecting to remote machine.
Hi, have you accessed the sharpSsh's author site
Using the source directly from author's site worked for us. many thanks for the help.
2

A straight forward way of preforming this using System.Diagnostics.Process


// Start the child process.
 Process p = new Process();
 // Redirect the error stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardError = true;
 p.StartInfo.FileName = "Write500Lines.exe";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected error stream.
 // p.WaitForExit();
 // Read the error stream first and then wait.
 string error = p.StandardError.ReadToEnd();
 p.WaitForExit();

1 Comment

Thanks Terrance. The C# application runs in a windows environment and i need to connect to remote unix box to execute the shell script there. Is there any direct method for this?
1

Even i had the same problem, i have googled for solution for around 1 month.

Finally, i have decided to use plink.exe (command line version of putty.exe) to connect to unix box and execute a script there.

You have to use plink through c# process, i have tried it and this works amazingly.

But rite now the problem i am facing is when i am running a script from c# process i am unable to pass arguments to that script. Probably it would be rite to say that i do not know how to do that.

Regards -Aakash

2 Comments

Hi Aakash, as OnesimusUnbound told check out sharpSSH from the orginal site, tamirgal.com/blog/page/SharpSSH.aspx
Yes Hari, but i i liked the plink rather than SharpSSH, plink is more stable.

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.