Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is quite easy to call plink without the shell popping up.</p> <p>The trick to not show a window is to set <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx" rel="nofollow noreferrer"><code>ProcessStartInfo.CreateNoWindow = true</code></a>.<br> Add some error handling to this and you're done.</p> <p>--- PlinkWrapper.cs ---</p> <pre><code>using System.Collections.Generic; using System.Diagnostics; namespace Stackoverflow_Test { public class PlinkWrapper { private string host { get; set; } /// &lt;summary&gt; /// Initializes the &lt;see cref="PlinkWrapper"/&gt; /// Assumes the key for the user is already loaded in PageAnt. /// &lt;/summary&gt; /// &lt;param name="host"&gt;The host, on format user@host&lt;/param&gt; public PlinkWrapper(string host) { this.host = host; } /// &lt;summary&gt; /// Runs a command and returns the output lines in a List&amp;lt;string&amp;gt;. /// &lt;/summary&gt; /// &lt;param name="command"&gt;The command to execute&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public List&lt;string&gt; RunCommand(string command) { List&lt;string&gt; result = new List&lt;string&gt;(); ProcessStartInfo startInfo = new ProcessStartInfo("plink.exe"); startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.CreateNoWindow = true; startInfo.Arguments = host + " " + command; using (Process p = new Process()) { p.StartInfo = startInfo; p.Start(); while (p.StandardOutput.Peek() &gt;= 0) { result.Add(p.StandardOutput.ReadLine()); } p.WaitForExit(); } return result; } } } </code></pre> <p>--- END PlinkWrapper.cs ---</p> <p>Call it like</p> <pre><code>PlinkWrapper plink = new PlinkWrapper("albin@mazarin"); foreach (var str in plink.RunCommand("pwd")) Console.WriteLine("&gt; " + str); </code></pre> <p>and the output will be like</p> <pre><code>&gt; /home/albin </code></pre> <p>The nice thing with <code>plink</code> is that it is well proven and integrates well with <code>pageant</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload