Note that there are some explanatory texts on larger screens.

plurals
  1. POConsole Application output is not shown
    text
    copied!<p>I have read several questions in StackOverflow about redirecting output/errors from application but It could not help me.</p> <p>I have developed an executable in C# code. It recovers software from system registry and call a webservice to save it to our database.</p> <p>Inside the executable we are printing messages with </p> <blockquote> <p>Console.WriteLine("Message from Executable");</p> </blockquote> <p>On the other hand we have a CRM application and I have written two win forms that call psexec.exe with the desired parameters and this .exe is remotely copied and launched on target machine.</p> <p>If you use direct psexec call with that parameters in cmd.exe, we can see the psexec execution banners and OUR executable output</p> <p>Something like:</p> <blockquote> <p>PsExec v1.98 - Execute processes remotely </p> <p>Copyright (C) 2001-2010</p> <p>Mark Russinovich Sysinternals - www.sysinternals.com</p> <p>Enterprise software @ 2012</p> <p><strong>Message from application</strong></p> <p>Starting task in machine "XXXXXXX" </p> <p>Recovering software list from registry</p> <p>Program.exe exited on MACHINE with error code 0.</p> </blockquote> <p>When I make the psexec call with .NET, I cant recover my application output, It just shows:</p> <blockquote> <p>PsExec v1.98 - Execute processes remotely </p> <p>Copyright (C) 2001-2010</p> <p>Mark Russinovich Sysinternals - www.sysinternals.com</p> <p>Program.exe exited on MACHINE with error code 0.</p> </blockquote> <p>I am assigning to Process class a delegate who is recovering async data from process, but this information, is not there.</p> <p>I paste some code to see If you can find the reason my C# Console application output does not appear:</p> <p>The command I launch is:</p> <pre><code>Dim CmdExe As String = "\\#MAQUINA# -u #USUARIO# -p #CLAVE# -s -c -f """ + executionPath + """" </code></pre> <p>Parametes -s (Run as system) -c (Copy local file to remote system) -f (force overwrite)</p> <pre><code>Private Sub LanzarProceso() CheckForIllegalCrossThreadCalls = False Dim Proceso As New Process AddHandler Proceso.OutputDataReceived, AddressOf CallbackProcesoAsync AddHandler Proceso.ErrorDataReceived, AddressOf ErrorDataReceivedAsync Dim startInfo As New ProcessStartInfo startInfo.FileName = execFile startInfo.Arguments = CmdExe.Replace("#MAQUINA#", txtFiltroMaquina.Text).Replace _ ("#USUARIO#", txtUsuario.Text.Trim).Replace _ ("#CLAVE#", txtClave.Text.Trim) Proceso.EnableRaisingEvents = True startInfo.UseShellExecute = False startInfo.RedirectStandardOutput = True startInfo.RedirectStandardError = True startInfo.CreateNoWindow = False Proceso.StartInfo = startInfo Proceso.Start() Proceso.BeginOutputReadLine() Proceso.BeginErrorReadLine() Proceso.WaitForExit() End Sub </code></pre> <p>Delegates handling data:</p> <pre><code> Private Sub CallbackProcesoAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs) If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then If Not listtask.InvokeRequired Then listtask.Items.Add(args.Data.ToString) Else Dim d As New TextToControl(AddressOf AddToControl) listtask.Invoke(d, args.Data.ToString) End If End If End Sub Private Sub ErrorDataReceivedAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs) If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then If Not listtask.InvokeRequired Then listtask.Items.Add(args.Data.ToString) Else Dim d As New TextToControl(AddressOf AddToControl) listtask.Invoke(d, args.Data.ToString) End If End If End Sub </code></pre> <p>I checked the program is finishing correctly. THe c# executable has</p> <pre><code>Enviroment.Exit(0); </code></pre> <p>at the end of the execution </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload