예제 #1
0
        private static void Main(string[] args)
        {
            Console.Title = "PowerShell Console Host";
            PSConsoleMain  pSConsoleMain = new PSConsoleMain();
            SyncTextReader @in           = new SyncTextReader(new BufferedStream(Console.OpenStandardInput()), Encoding.Default);

            Console.SetIn(@in);
            if (args.Length < 1)
            {
                ConsoleColor foregroundColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("    PowerShell Console Host");
                Console.WriteLine("    =====================================");
                Console.WriteLine("");
                Console.WriteLine("PowerShell.exe does not use StdIn/StdOut");
                Console.WriteLine("So I made console host");
                Console.WriteLine("PSConsole.exe [ps1 file] : Script Mode. Run PS Script and Exit.");
                Console.WriteLine("PSConsole.exe : Command line mode.");
                Console.WriteLine("");
                Console.ForegroundColor = foregroundColor;
                pSConsoleMain.Run();
                return;
            }
            if (!args[0].EndsWith(".ps1"))
            {
                Console.WriteLine("Script file must end with .ps1.");
                Environment.Exit(-1);
                return;
            }
            FileInfo fileInfo = new FileInfo(args[0]);

            if (fileInfo.Exists)
            {
                string text = fileInfo.FullName;
                if (args.Length > 1)
                {
                    for (int i = 1; i < args.Length; i++)
                    {
                        text = text + " " + args[i];
                    }
                }
                pSConsoleMain.Execute(text);
                Environment.Exit(pSConsoleMain.ExitCode);
                return;
            }
            Console.WriteLine("Script file [{0}] does not exist.", args[0]);
            Environment.Exit(-1);
        }
예제 #2
0
 public ConsoleHost(PSConsoleMain program)
 {
     this.program = program;
 }