public static RubyIO /*!*/ OpenPipe(RubyContext /*!*/ context, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ command, [DefaultProtocol, Optional, NotNull] MutableString modeString) { bool preserveEndOfLines; IOMode mode = RubyIO.ParseIOMode(modeString.ConvertToString(), out preserveEndOfLines); ProcessStartInfo startInfo = KernelOps.GetShell(context, command); startInfo.UseShellExecute = false; if (mode == IOMode.ReadOnlyFromStart) { startInfo.RedirectStandardOutput = true; } else if (mode == IOMode.WriteOnlyAppend || mode == IOMode.WriteOnlyTruncate) { startInfo.RedirectStandardInput = true; } else { startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true; } Process process; try { process = Process.Start(startInfo); } catch (Exception e) { throw new Errno.NoEntryError(startInfo.FileName, e); } context.ChildProcessExitStatus = new RubyProcess.Status(process); StreamReader reader = null; StreamWriter writer = null; if (startInfo.RedirectStandardOutput) { reader = process.StandardOutput; } if (startInfo.RedirectStandardInput) { writer = process.StandardInput; } return(new RubyIO(context, reader, writer, modeString.ConvertToString())); }
private static Stream /*!*/ OpenFileStream(RubyContext /*!*/ context, string /*!*/ path, string /*!*/ modeString) { FileMode mode; FileAccess access; // ignore "b": bool preserveEndOfLines; switch (RubyIO.ParseIOMode(modeString, out preserveEndOfLines)) { case IOMode.ReadOnlyFromStart: mode = FileMode.Open; access = FileAccess.Read; break; case IOMode.ReadWriteFromStart: mode = FileMode.Open; access = FileAccess.ReadWrite; break; case IOMode.WriteOnlyTruncate: mode = FileMode.Create; access = FileAccess.Write; break; case IOMode.ReadWriteTruncate: mode = FileMode.Create; access = FileAccess.ReadWrite; break; case IOMode.WriteOnlyAppend: mode = FileMode.Append; access = FileAccess.Write; break; case IOMode.ReadWriteAppend: mode = FileMode.Append; access = FileAccess.ReadWrite; break; default: throw RubyIO.IllegalMode(modeString); } return(context.DomainManager.Platform.OpenInputFileStream(path, mode, access, FileShare.ReadWrite)); }