예제 #1
0
        public Command Execute(string baseDirectory, bool wait = true)
        {
            AsynchronousCommandInfo asynchronousCommandInfo = null;

            if (!wait)
            {
                asynchronousCommandInfo = new AsynchronousCommandInfo(Result, Executable, Arguments);
                InstanceRegistry.Publish(asynchronousCommandInfo);
            }

            Result = new CommandResult(this);
            Result.Get(baseDirectory, wait);

            if (!wait)
            {
                Task.Factory.StartNew(() =>
                {
                    Result.Wait();
                    asynchronousCommandInfo.Output = Result.Output;
                    InstanceRegistry.Unpublish(asynchronousCommandInfo);
                });
                ContextSwitch.Go();
            }

            return this;
        }
예제 #2
0
 public CommandExecutor(CommandResult result)
 {
     this.result = result;
 }
예제 #3
0
 private string GetCommandArgs(CommandResult result)
 {
     if (result.Command.Type == CommandType.Cmd)
         return string.Format("/c {0}", DoubleQuoteWrap(result.Command.Executable));
     if (result.Command.Type == CommandType.CmdWithWait)
         return string.Format("/c start /wait {0}", DoubleQuoteWrap(result.Command.Executable));
     if (result.Command.Type == CommandType.Vanilla)
         return string.Join(" ", result.Command.Arguments);
     if (result.Command.Type == CommandType.Powershell)
         return "-executionpolicy unrestricted " + string.Join(" ", DoubleQuoteWrap(result.Command.Executable));
     return string.Format("/c {0}", DoubleQuoteWrap(result.Command.Executable));
 }
예제 #4
0
 private string GetCommand(CommandResult result)
 {
     if (result.Command.Type == CommandType.Cmd)
         return Path.Combine(Environment.GetEnvironmentVariable("windir"), "system32\\cmd.exe");
     if (result.Command.Type == CommandType.CmdWithWait)
         return Path.Combine(Environment.GetEnvironmentVariable("windir"), "system32\\cmd.exe");
     if (result.Command.Type == CommandType.Vanilla)
         return result.Command.Executable;
     if (result.Command.Type == CommandType.Powershell)
         /*
         32 bit version : C:\Windows\System32\WindowsPowerShell\v1.0
         64 bit version : C:\Windows\SysWOW64\WindowsPowerShell\v1.0
         */
         return "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
     return "cmd.exe";
 }