/// <summary> /// Execute with timeout /// </summary> /// <param name="shell"></param> /// <param name="commandToExecute"></param> /// <param name="timeout"></param> /// <returns></returns> public static Task <string> ExecuteCommandAsync(this ISecureShell shell, string commandToExecute, TimeSpan timeout) { using (var cts = new CancellationTokenSource(timeout)) { return(shell.ExecuteCommandAsync(commandToExecute, cts.Token)); } }
/// <summary> /// Run command /// </summary> /// <param name="shell"></param> /// <param name="options"></param> /// <returns></returns> private static async Task ExecuteCommandAsync(ISecureShell shell, CliOptions options) { var str = await shell.ExecuteCommandAsync( options.GetValue <string>("-c", "--command")); PrintResult(options, str); }
/// <summary> /// Execute with default timeout of 3 minutes /// </summary> /// <param name="shell"></param> /// <param name="commandToExecute"></param> /// <returns></returns> public static Task <string> ExecuteCommandAsync(this ISecureShell shell, string commandToExecute) { return(shell.ExecuteCommandAsync(commandToExecute, TimeSpan.FromMinutes(3))); }
/// <summary> /// Execute with timeout /// </summary> /// <param name="shell"></param> /// <param name="commandToExecute"></param> /// <param name="timeout"></param> /// <returns></returns> public static Task <string> ExecuteCommandAsync(this ISecureShell shell, string commandToExecute, TimeSpan timeout) => shell.ExecuteCommandAsync(commandToExecute, new CancellationTokenSource(timeout).Token);