Beispiel #1
0
		public void BeginOutputReadLine ()
		{
			if (process_handle == IntPtr.Zero || output_stream == null || StartInfo.RedirectStandardOutput == false)
				throw new InvalidOperationException ("Standard output has not been redirected or process has not been started.");

			if ((async_mode & AsyncModes.SyncOutput) != 0)
				throw new InvalidOperationException ("Cannot mix asynchronous and synchonous reads.");

			async_mode |= AsyncModes.AsyncOutput;
			output_canceled = false;
			if (async_output == null) {
				async_output = new ProcessAsyncReader (this, stdout_rd, true);
				async_output.ReadHandler.BeginInvoke (null, async_output);
			}
		}
Beispiel #2
0
		public void BeginErrorReadLine ()
		{
			if (process_handle == IntPtr.Zero || error_stream == null || StartInfo.RedirectStandardError == false)
				throw new InvalidOperationException ("Standard error has not been redirected or process has not been started.");

			if ((async_mode & AsyncModes.SyncError) != 0)
				throw new InvalidOperationException ("Cannot mix asynchronous and synchonous reads.");

			async_mode |= AsyncModes.AsyncError;
			error_canceled = false;
			if (async_error == null) {
				async_error = new ProcessAsyncReader (this, stderr_rd, false);
				async_error.ReadHandler.BeginInvoke (null, async_error);
			}
		}
Beispiel #3
0
			public void AddInput (ProcessAsyncReader reader)
			{
				lock (this) {
					int nread = stream.Read (buffer, 0, buffer.Length);
					if (nread == 0) {
						IsCompleted = true;

						Flush (true);
						if (err_out)
							process.OnOutputDataReceived (null);
						else
							process.OnErrorDataReceived (null);

						return;
					}

					try {
						sb.Append (Encoding.Default.GetString (buffer, 0, nread));
					} catch {
						// Just in case the encoding fails...
						for (int i = 0; i < nread; i++) {
							sb.Append ((char) buffer [i]);
						}
					}

					Flush (false);

					IOSelector.Add (this.handle, new IOSelectorJob (IOOperation.Read, s => AddInput ((ProcessAsyncReader) s), this));
				}
			}