Jose Velasquez

Generation

generate functionSun, 18 Jun 2023

script linux ejecutar comando y password

# private string Execute(string user, string password, string hostname, string command) { var result = string.Empty; var info = new ProcessStartInfo("ssh", user + "@" + hostname + " " + command) { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false }; using (var proc = Process.Start(info)) { if (proc != null) { proc.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data); proc.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); } } return result; }

Questions about programming?Chat with your personal AI assistant