Esempio n. 1
0
        private void Listen()
        {
            string stdin = null;

Start:
            stdin = null;
            stdin = Console.ReadLine();


            if (!string.IsNullOrEmpty(stdin) && !string.IsNullOrWhiteSpace(stdin))
            {
                //Count Double Inverted Commas
                int commaCount = 0;
                foreach (char c in stdin)
                {
                    if (c.ToString() == "\"")
                    {
                        commaCount++;
                    }
                }

                double rm = 0; //Check if num of d inverted commas is uneven
                rm = commaCount % 2;
                string read = null;
                if (!rm.Equals(0))
                {
append:             //append stdin until comma is even
                    format.ConsoleColorWrite(":>", ConsoleColor.Cyan, true);
                    read = Console.ReadLine();
                    bool found = false;
                    foreach (char c in read)
                    {
                        if (!c.ToString().Equals("\"") && !found)
                        {
                            stdin = stdin + c;
                        }
                        else
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        goto append;
                    }
                }
                Starter(stdin);
                Console.WriteLine();
                format.ConsoleColorWrite(ShellWorkingDirectory, ConsoleColor.Cyan, true);
                goto Start;
            }
            else
            {
                format.ConsoleColorWrite(ShellWorkingDirectory, ConsoleColor.Cyan, true);
                goto Start;
            }
        }
Esempio n. 2
0
        public bool Execute(string cmd, List <string> arguments)
        {
            string Arguments = null;

            foreach (string arg in arguments)
            {
                Arguments += " " + arg;
            }

            Process          process  = new Process();
            ProcessStartInfo property = new ProcessStartInfo(cmd)
            {
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                Arguments = Arguments,
            };

            process.StartInfo = property;

            // Depending on your application you may either prioritize the IO or the exact opposite
            Thread outputThread = new Thread(outputReader)
            {
                Name = "ChildIO Output", IsBackground = true
            };
            Thread errorThread = new Thread(errorReader)
            {
                Name = "ChildIO Error", IsBackground = true
            };
            Thread inputThread = new Thread(inputReader)
            {
                Name = "ChildIO Input", IsBackground = true
            };

            // Start the IO threads
            try
            {
                process.Start();
                //start reader threads
                outputThread.Start(process);
                errorThread.Start(process);
                inputThread.Start(process);
            } catch (Exception x)
            {
                if (x.ToString().Contains("requires elevation"))
                {
                    Console.WriteLine("Rashell: Unable to start application \"" + cmd + "\"" + ".");
                    format.ConsoleColorWrite("Requires Elevation", ConsoleColor.Red, false);

                    Console.Write("You want to restart Rashell with Elevated Priviledges? (Y/N):");
                    string reply = Console.ReadLine().ToLower();

                    reply = format.RemoveTab(reply);
                    reply = format.RemoveSpace(reply);

                    if (reply == "y" || reply == "yes")
                    {
                        //shell.restartAsAdmin();
                    }
                    else
                    {
                        goto KillThreads;
                    }
                }
                else if (x.ToString().Contains("specified executable is not a valid"))
                {
                    Console.WriteLine("Rashell: Unable to start \"" + cmd + "\"" + ".");
                    format.ConsoleColorWrite("Invalid File Type", ConsoleColor.Red, false);

                    goto KillThreads;
                }
                else
                {
                    Console.WriteLine("Rashell: Unable to start \"" + cmd + "\"" + ".");
                    format.ConsoleColorWrite("Unknown Error", ConsoleColor.Yellow, false);

                    goto KillThreads;
                }
            }

            // Signal to end the application
            ManualResetEvent stopApp = new ManualResetEvent(false);

            // Enables the exited event and set the stopApp signal on exited
            process.EnableRaisingEvents = true;
            process.Exited += (e, sender) => { stopApp.Set(); };

            // Wait for the child app to stop
            stopApp.WaitOne();

            // Kill all started threads when child ends.
KillThreads:


            return(true);
        }