Calling unix shell script remotely from C#

前端 未结 3 1452
陌清茗
陌清茗 2021-02-04 19:09

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 e

相关标签:
3条回答
  • 2021-02-04 19:24

    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

    0 讨论(0)
  • 2021-02-04 19:39

    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.
    0 讨论(0)
  • 2021-02-04 19:39

    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();
    
    
    0 讨论(0)
提交回复
热议问题