¿Cómo se ejecuta el comando a través del shell y se devuelve el resultado completo como una cadena usando C#?C# equivalente a shell_exec
equivalente a shell_exec() de PHP.
Gracias, avanzado.
¿Cómo se ejecuta el comando a través del shell y se devuelve el resultado completo como una cadena usando C#?C# equivalente a shell_exec
equivalente a shell_exec() de PHP.
Gracias, avanzado.
La documentación MSDN documentation on Process.StandardOutput muestra un ejemplo
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Es posible que como para extraer el flujo de error estándar también.
Utilice la clase Process
vistazo a la clase de proceso y Standard OutputStandard Error y los OutputDataReceived y ErrorDataReceived eventos recibimos.
Hay un CodeProject article here, que puede ser útil.
funciona bien, gracias! –