How do I check if another application is busy?
I have a program that sends text to a console. The text that I will send contains #13 char (e.g. ls#13cd documents#13dir). In other words I want to send many commands at one time and the console will process them one by one. I am sending the text character by character. Sometimes the console only executes ls and cd documents. I think maybe this is because my program continuously sends character even if the console is busy, in which case the console does not receive incoming characters.
This is my code:
procedure TForm1.SendTextToAppO(Str: String; AHandle: Integer); var iWindow, iPoint, i: Integer; SPass: PChar; sList: TStringList; begin sList := TStringList.Create; ExtractStrings([#13],[' '],PChar(Str),sList); iWindow := AHandle;// AHandle is the handle of the console iPoint := ChildWindowFromPoint(iWindow, Point(50,50)); for i:=0 to sList.Count-1 do begin SPass := PChar(sList[i]); try while(SPass^ <> #$00) do begin SendMessage(iPoint,WM_CHAR,Ord(SPass^),0); Inc(SPass); end; SendMessage(iPoint,WM_KEYDOWN,VK_RETURN,0); except // do nothing; end; end; end;
I am using Delphi 7.
If I interpret you question correctly you are sending the text to some sort of shell/command line interpreter and you want it to execute your commands.
Usually command line interpreters output a certain prompt (like $ on a Linux system or C:\ for DOS) that indicate that they can accept new commands. You need to read the output to wait for the appropriate prompt before you send another command. If you don’t your sent text will be consumed as input by the currently running command (like you experienced).