Jose Velasquez

Generation

generate functionSun, 18 Jun 2023

script linux ejecutar comando y password

using System; using System.Text; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; public class ExecuteCommand { public static void Main() { string command = "ifconfig"; string password = "123"; ExecuteCommandSync(command, password); } public static void ExecuteCommandSync(object command, object password) { try { ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/c " + command); processStartInfo.RedirectStandardOutput = true; processStartInfo.UseShellExecute = false; processStartInfo.CreateNoWindow=true; processStartInfo.RedirectStandardInput = true; processStartInfo.RedirectStandardError = true; Process process = Process.Start(processStartInfo); process.StandardInput.WriteLine(password); process.StandardInput.Flush(); process.StandardInput

Questions about programming?Chat with your personal AI assistant