public override void Execute() { if (proc == IntPtr.Zero) { var cmd = new AccessCommandPrompt(); cmd.Perform(); //Take the proc for ourselves... we can't just call base.Execute, as we have already cannabalized // our version of AccessCommandPrompt by interfering with freeTitle. this.proc = cmd.Handle; } prevPrompt = this.getTitle(); this.Run(command); string promptPrefix = this.getTitle().Substring("AutoShell SUB ".Length); int index = promptPrefix.IndexOf(":"); if (index < 0) { throw new Exception("Do not know how to identify this SSH prompt, I should write code for this case so it doesn't have to crash (although it will always be less useful to not identify when the shell is reading for input"); } promptPrefix = promptPrefix.Substring(0, index); }
public static void Run(this AccessCommandPrompt prompt, string command, bool dontBlock = false, Action beforeBlock = null, bool noDelay = false) { if (prompt == null) { prompt = new AccessCommandPrompt(); prompt.Perform(); } Clipboard.SetText(command + "\r\n"); SendMessage(prompt.Handle, WM_COMMAND, PASTE_IN_COMMAND_PROMPT, 0); if (!noDelay) { //Wait until the command starts... because I am a bad programmer. Could totally fix this by properly // talking to AutoShell, but you know... not enough time Thread.Sleep(100); } if (!dontBlock) { if (beforeBlock != null) { beforeBlock(); } //Poll until it is done while (!prompt.isFreeTitle(prompt.getTitle())) { Thread.Sleep(50); } } }