Creates and executes the command.
Namespace: Renci.SshNetAssembly: Renci.SshNet (in Renci.SshNet.dll) Version: 0.1.0.0 (1.0.0.0)
Syntax
public SshCommand RunCommand( string commandText )
Parameters
- commandText
- Type:
System String
The command text.
Return Value
Returns an instance of SshCommand with execution results.Exceptions
| Exception | Condition |
|---|---|
| CommandText property is empty. | |
| Renci.SshNet.Common SshException | Invalid Operation - An existing channel was used to execute this command. |
| Asynchronous operation is already in progress. | |
| Renci.SshNet.Common SshConnectionException | Client is not connected. |
| commandText is null. |
Remarks
Examples
client.Connect(); var testValue = Guid.NewGuid().ToString(); var command = client.RunCommand(string.Format("echo {0}", testValue)); var result = command.Result; result = result.Substring(0, result.Length - 1); // Remove \n character returned by command client.Disconnect();
System.Threading.Tasks.Parallel.For(0, 10000, () => { var client = new SshClient(host, username, password); client.Connect(); return client; }, (int counter, ParallelLoopState pls, SshClient client) => { var result = client.RunCommand("echo 123"); Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); return client; }, (SshClient client) => { client.Disconnect(); client.Dispose(); } );
See Also