/// <summary> /// System.Diagnostics.Process.BeginOutputReadLine の一文字毎版。 /// BeginOutputReadLine だと、行末に来るか、プログラムが終了するまで、次のデータが送られてこない。 /// 其処で、行末が来なくても読み取った側から文字列を通知する様に改造した。 /// </summary> public static mwg.IO.AsyncStringReader BeginOutputReadString(this Diag::Process process) { ProcessReflector proc = new ProcessReflector(process); switch (proc.outputStreamReadMode) { case SyncReadMode.MODE_UNDEF: proc.outputStreamReadMode = SyncReadMode.MODE_ASYNC; break; case SyncReadMode.MODE_SYNC: throw new System.InvalidOperationException("CantMixSyncAsyncOperation"); } if (proc.pendingOutputRead) { throw new System.InvalidOperationException("PendingAsyncOperation"); } proc.pendingOutputRead = true; System.IO.StreamReader standardOutput = proc.standardOutput; if (standardOutput == null) { throw new System.InvalidOperationException("CantGetStandardOut"); } mwg.IO.AsyncStringReader reader = new mwg.IO.AsyncStringReader( standardOutput.BaseStream, proc.OutputReadNotifyUser, standardOutput.CurrentEncoding ); reader.BeginRead(); return(reader); }
public static mwg.IO.AsyncStringReader BeginErrorReadString(this Diag::Process proc) { const int MODE_UNDEF = 0; //const int MODE_SYNC=1; const int MODE_ASYNC = 2; int errorStreamReadMode = (int)fProcess_errorStreamReadMode.GetValue(proc); if (errorStreamReadMode == MODE_UNDEF) { fProcess_errorStreamReadMode.SetValue(proc, MODE_ASYNC); } else if (errorStreamReadMode != MODE_ASYNC) { throw new System.InvalidOperationException("CantMixSyncAsyncOperation"); } if ((bool)fProcess_pendingErrorRead.GetValue(proc)) { throw new System.InvalidOperationException("PendingAsyncOperation"); } fProcess_pendingErrorRead.SetValue(proc, true); mwg.IO.AsyncStringReader reader; { System.IO.StreamReader standardError = (System.IO.StreamReader)fProcess_standardError.GetValue(proc); if (standardError == null) { throw new System.InvalidOperationException("CantGetStandardError"); } System.IO.Stream stream = standardError.BaseStream; System.Action <string> callback = (System.Action <string>)System.Delegate.CreateDelegate( typeof(System.Action <string>), proc, "ErrorReadNotifyUser"); reader = new mwg.IO.AsyncStringReader(stream, (System.Action <string>)callback, standardError.CurrentEncoding); } reader.BeginRead(); return(reader); }