.net - the problem of redirecting stdout in c# -


Can you please tell why the shell does not work with the redirection system. Diagnostics Process class? I am trying to redirect the output stream to file with the following snippet:

  process p = new process (); P.StartInfo = New ProcstyTinfo (); P.StartInfo.FileName = "java.exe"; P.StartInfo.Arguments = @ "& gt; c: \ temp \ test.log2> and 1"; P.StartInfo.UseShellExecute = True; P.Start ();  

The same code works without problems with Python Reading output stream does not seem to be a better solution in my case programmatic as there will be a bunch of processes launched by my application.

You can not redial because no shell is included directly. You can run a CMD.axa session, but using the appropriate method RedirectStandardOutput / Error Properties, there are no problems when there are several processes, this is a class for which I use it.

  Class HandleAccactable {Personal Data RECAvid Handler Output Handler; Public DataReceivedEventHandler OutputHandler {Set {outputHandler = value; }} Private Detroit Wide Documents Handler Errorhandler; Public DataReceivedEventHandler ErrorHandler {Set {errorHandler = value; }} Public Null Call Wont (string executable, string arguments) {string commandLine = executable; String args = args; ProcessStartInfo psi = New ProcessTinfo (Commandline); Psi.UseShellExecute = false; Psi.LoadUserProfile = false; Psi.RedirectStandardOutput = true; Psi.RedirectStandardError = true; Psi.WindowStyle = Process WindowStyle.Minimized; Psi.CreateNoWindow = True; Psi.Arguments = args; P = new process (); P.StartInfo = psi; Try {p.start (); P.BeginOutputReadLine (); P.BeginErrorReadLine (); If (outputhandler! = Null) p.OutputDataReceived + = outputHandler; If (errorHandler! = Null) p.ErrorDataReceived + = ErrorHandler; P.WaitForExit (); P.Close (); P.Dispose (); } Hold (exception before) {log. Error (ex.Message); }}} // another class void at p_ErrorDataReceived (Object Sender, DataReceivedEventArgs E) {// Handle STDERR if (e.Data! = Null & E.Data.Equals ("")) {if (! E .Data.Contains ("some")} {}}} zero p_OutputDataReceived (Object Sender, DataReceivedEventArgs E) {// Handle STDOUT if (E. data! = Null & amp; E.Data.Equals ("")) {}} Handle Detectable = New Handle Eligible (); He.OutputHandler = p_OutputDataReceived; He.ErrorHandler = p_ErrorDataReceived; She is Cubidepable (@ "C: \ Java .exe", "- CPF Classname");  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -