Process.start: how to get the output?

后端 未结 9 1419
無奈伤痛
無奈伤痛 2020-11-21 23:56

I would like to run an external command line program from my Mono/.NET app. For example, I would like to run mencoder. Is it possible:

  1. To get
9条回答
  •  情话喂你
    2020-11-22 00:56

    The solution that worked for me in win and linux is the folling

    // GET api/values
            [HttpGet("cifrado/{xml}")]
            public ActionResult> Cifrado(String xml)
            {
                String nombreXML = DateTime.Now.ToString("ddMMyyyyhhmmss").ToString();
                String archivo = "/app/files/"+nombreXML + ".XML";
                String comando = " --armor --recipient bibankingprd@bi.com.gt  --encrypt " + archivo;
                try{
                    System.IO.File.WriteAllText(archivo, xml);                
                    //String comando = "C:\\GnuPG\\bin\\gpg.exe --recipient licorera@local.com --armor --encrypt C:\\Users\\Administrador\\Documents\\pruebas\\nuevo.xml ";
                    ProcessStartInfo startInfo = new ProcessStartInfo() {FileName = "/usr/bin/gpg",  Arguments = comando }; 
                    Process proc = new Process() { StartInfo = startInfo, };
                    proc.StartInfo.RedirectStandardOutput = true;
                    proc.StartInfo.RedirectStandardError = true;
                    proc.Start();
                    proc.WaitForExit();
                    Console.WriteLine(proc.StandardOutput.ReadToEnd());
                    return new string[] { "Archivo encriptado", archivo + " - "+ comando};
                }catch (Exception exception){
                    return new string[] { archivo, "exception: "+exception.ToString() + " - "+ comando };
                }
            }
    

提交回复
热议问题