private void BeginRedirectedConsoleOutput(
            out TextWriter savedOutput
            )
        {
            savedOutput = Console.Out;

            ConsoleRedirect redirector = new ConsoleRedirect(c_Output);

            Console.SetOut(redirector);
        }
        private void EndRedirectedConsoleOutput(
            ref TextWriter savedOutput
            )
        {
            ConsoleRedirect redirector = Console.Out as ConsoleRedirect;

            Console.SetOut(savedOutput);

            if (redirector != null)
            {
                redirector.Dispose();
                redirector = null;
            }

            savedOutput = null;
        }
Beispiel #3
0
        private int ExecuteThread(string commands)
        {
            Result result  = null;
            var    c       = new ConsoleRedirect();
            var    old_out = Console.Out;

            Console.SetOut(c);
            c.Output    += c_Output;
            _interpreter = Interpreter.Create(ref result);


            ICommand command = new DccCommand(new CommandData(
                                                  "dcc", null, null, null, typeof(DccCommand).FullName,
                                                  CommandFlags.None, null, 0));

            ReturnCode code;
            long       token = 0;

            code = _interpreter.AddCommand(
                command, null, ref token, ref result);

            code = _interpreter.AddCommand(new EchoCommand(new CommandData(
                                                               "echo", null, null, null, typeof(EchoCommand).FullName,
                                                               CommandFlags.None, null, 0)), null, ref token, ref result);

            if (code == ReturnCode.Ok)
            {
                int errorLine = 0;

                code = _interpreter.EvaluateScript(commands,
                                                   ref result, ref errorLine);
                _interpreter.Host.WriteResult(code, result, errorLine, true);
                return((int)_interpreter.ExitCode);
            }
            else
            {
                _interpreter.Host.WriteResult(code, result, true);
            }
            _interpreter.Dispose();
            _interpreter = null;
            Console.SetOut(old_out);
            return(0);
        }
        private int ExecuteThread(string commands)
        {
            Result result = null;
            var c = new ConsoleRedirect();
            var old_out = Console.Out;
            Console.SetOut(c);
            c.Output += c_Output;
            _interpreter = Interpreter.Create(ref result);
           

                ICommand command = new DccCommand(new CommandData(
                    "dcc", null, null, null, typeof(DccCommand).FullName,
                    CommandFlags.None, null, 0));

                ReturnCode code;
                long token = 0;

                code = _interpreter.AddCommand(
                    command, null, ref token, ref result);

                code = _interpreter.AddCommand(new EchoCommand(new CommandData(
                    "echo", null, null, null, typeof(EchoCommand).FullName,
                    CommandFlags.None, null, 0)), null, ref token, ref result);

                if (code == ReturnCode.Ok)
                {
                    int errorLine = 0;

                    code = _interpreter.EvaluateScript(commands,
                        ref result, ref errorLine);
                    _interpreter.Host.WriteResult(code, result, errorLine, true);
                    return (int) _interpreter.ExitCode;
                }
                else
                {
                    _interpreter.Host.WriteResult(code, result, true);
                }
            _interpreter.Dispose();
            _interpreter = null;
            Console.SetOut(old_out);
            return 0;
        }