示例#1
0
        public static PythonFile OpenPipedCommand(ICallerContext context, string command, string mode, int bufsize)
        {
            if (String.IsNullOrEmpty(mode))
            {
                mode = "r";
            }
            ProcessStartInfo psi = GetProcessInfo(command);
            Process          p;
            PythonFile       res;

            switch (mode)
            {
            case "r":
                psi.RedirectStandardOutput = true;
                p = Process.Start(psi);

                res = new POpenFile(context, command, p, p.StandardOutput.BaseStream, "r");
                break;

            case "w":
                psi.RedirectStandardInput = true;
                p = Process.Start(psi);

                res = new POpenFile(context, command, p, p.StandardInput.BaseStream, "w");
                break;

            default:
                throw Ops.ValueError("expected 'r' or 'w' for mode, got {0}", mode);
            }

            return(res);
        }
示例#2
0
文件: nt.cs 项目: jcteague/ironruby
        public static PythonFile popen(CodeContext/*!*/ context, string command, string mode, int bufsize) {
            if (String.IsNullOrEmpty(mode)) mode = "r";
            ProcessStartInfo psi = GetProcessInfo(command);
            psi.CreateNoWindow = true;  // ipyw shouldn't create a new console window
            Process p;
            PythonFile res;

            try {
                switch (mode) {
                    case "r":
                        psi.RedirectStandardOutput = true;
                        p = Process.Start(psi);

                        res = new POpenFile(context, command, p, p.StandardOutput.BaseStream, "r");
                        break;
                    case "w":
                        psi.RedirectStandardInput = true;
                        p = Process.Start(psi);

                        res = new POpenFile(context, command, p, p.StandardInput.BaseStream, "w");
                        break;
                    default:
                        throw PythonOps.ValueError("expected 'r' or 'w' for mode, got {0}", mode);
                }
            } catch (Exception e) {
                throw ToPythonException(e);
            }

            return res;
        }
示例#3
0
        public static PythonFile OpenPipedCommand(ICallerContext context, string command, string mode, int bufsize)
        {
            if (String.IsNullOrEmpty(mode)) mode = "r";
            ProcessStartInfo psi = GetProcessInfo(command);
            Process p;
            PythonFile res;

            try {
                switch (mode) {
                    case "r":
                        psi.RedirectStandardOutput = true;
                        p = Process.Start(psi);

                        res = new POpenFile(context, command, p, p.StandardOutput.BaseStream, "r");
                        break;
                    case "w":
                        psi.RedirectStandardInput = true;
                        p = Process.Start(psi);

                        res = new POpenFile(context, command, p, p.StandardInput.BaseStream, "w");
                        break;
                    default:
                        throw Ops.ValueError("expected 'r' or 'w' for mode, got {0}", mode);
                }
            } catch (Exception e) {
                throw ToPythonException(e);
            }

            return res;
        }