public Program(int pid, Stream stdout = null, Stream stdin = null, Stream stderr = null)
                {
                    Running = false;
                    Pid     = pid;
                    Events  = new Queue <ProgramEvent>();

                    if (stdout == null)
                    {
                        stdout = new NixStream();
                    }
                    StdOut = stdout;
                    if (stdin == null)
                    {
                        NixStream s = new NixStream();
                        s.EchoStream = true;
                        stdin        = s;
                    }
                    InputStream = stdin;
                    if (stderr == null)
                    {
                        stderr = new NixStream();
                    }
                    StdErr      = stderr;
                    MainThread  = new System.Threading.Thread(RunHandler);
                    InputThread = new System.Threading.Thread(InputRun);
                }
            public static void SetEchoStream(this System.IO.Stream stream, bool value)
            {
                NixStream nixStream = stream as NixStream;

                if (nixStream != null)
                {
                    nixStream.EchoStream = value;
                }
            }
Beispiel #3
0
            // Use this for initialization
            void Start()
            {
                /*
                 * var ScriptEngine = IronPython.Hosting.Python.CreateEngine();
                 * // and the scope (ie, the python namespace)
                 * var ScriptScope = ScriptEngine.CreateScope();
                 *
                 * // execute a string in the interpreter and grab the variable
                 * string example = "f = open('testfile', 'w')\nf.write('Testoutput')\nf.close()";
                 *
                 * var ScriptSource = ScriptEngine.CreateScriptSourceFromString(example);
                 * ScriptSource.Execute(ScriptScope);
                 * string came_from_script = ScriptScope.GetVariable<string>("output");
                 * // Should be what we put into 'output' in the script.
                 * Debug.Log(came_from_script);
                 *
                 * var ScriptEngine = IronPython.Hosting.Python.CreateEngine();
                 * // and the scope (ie, the python namespace)
                 * var ScriptScope = ScriptEngine.CreateScope();
                 * // execute a string in the interpreter and grab the variable
                 * string example = "from System.Collections import BitArray\nba = BitArray(5)\nba.Set(0, False)\noutput = ba[0]";
                 *
                 * var ScriptSource = ScriptEngine.CreateScriptSourceFromString(example);
                 * ScriptSource.Execute(ScriptScope);
                 * bool came_from_script = ScriptScope.GetVariable<bool>("output");
                 * // Should be what we put into 'output' in the script.
                 * Debug.Log(came_from_script);
                 */

                InputBuffer = "";
                Lua.LuaOptions opts = new Lua.LuaOptions();
                opts.ExecuteHandler = ExecuteHandler;
                StdIn      = new NixStream();
                opts.StdIn = StdIn;
                //stdin.Write ("Melli\n");

                /*Thread t = new Thread(() =>
                 *                    {
                 *  Thread.Sleep(2000);
                 *  //Console.WriteLine("Waiting for use input: ");
                 *  //string input = Console.ReadLine();
                 *  //stdin.Write(input + "\n");
                 *  stdin.Write("Melli\n");
                 * });
                 * t.Start();*/

                Thread t2 = new Thread(() =>
                {
                    Lua l = new Lua(opts);
                    l.DoString(@"os.execute('hello: ')
				s = io.read('*l')
				os.execute('how are you? '..s)"                );
                });

                t2.Start();
            }
            public static bool GetEchoStream(this System.IO.Stream stream)
            {
                NixStream nixStream = stream as NixStream;

                if (nixStream != null)
                {
                    return(nixStream.EchoStream);
                }
                return(true);
            }
            public static int Read(this System.IO.Stream stream, ref string buffer, int maxRead = -1)
            {
                NixStream nixStream = stream as NixStream;

                if (nixStream != null)
                {
                    return(nixStream.ReadString(ref buffer, maxRead));
                }
                return(0);
            }
            public static void WriteLine(this System.IO.Stream stream, string buffer)
            {
                NixStream nixStream = stream as NixStream;

                if (nixStream != null)
                {
                    nixStream.WriteStringLine(buffer);
                    return;
                }
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(buffer + "\n");
                stream.Write(bytes, 0, bytes.Length);
            }
Beispiel #7
0
                public void Execute(string input)
                {
                    List <string> result = Parse(input);

                    if (result.Count == 1)
                    {
                        MainSystem.Execute(MainSession, result[0]);
                    }
                    else if (result.Count > 1)
                    {
                        string args    = "";
                        string operand = null;
                        string args2   = "";
                        args = result[0];
                        if (result.Count >= 3)
                        {
                            operand = result[1];
                            args2   = result[2];
                        }

                        if (args2.Length == 0)
                        {
                            MainSystem.Execute(MainSession, args);
                        }
                        else
                        {
                            if (operand == ">" || operand == "<")
                            {
                                NixPath filePath = new NixPath(args2);
                                NixPath path     = OpenPath(filePath);
                                using (Stream fstream = MainSystem.RootDrive.OpenFile(path, FileAccess.Write, FileMode.Create))
                                {
                                    if (operand == ">")
                                    {
                                        MainSystem.Execute(MainSession, args, fstream, null);
                                    }
                                    else if (operand == "<")
                                    {
                                        MainSystem.Execute(MainSession, args, null, fstream);
                                    }
                                }
                            }
                            else if (operand == "|")
                            {
                                NixStream tmp = new NixStream();
                                MainSystem.Execute(MainSession, args, tmp, null);
                                MainSystem.Execute(MainSession, args2, null, tmp);
                            }
                        }
                    }
                }
 public static void WriteLine(this NixStream stream, string buffer)
 {
     stream.WriteStringLine(buffer);
 }