I recommend to use my library UnTerminal https://github.com/t-edson/UnTerminal.
It's a wrapper for TProccess that include events. Check the sample projects for a simple use.
thanks but not sure that will work with console apps! have you done any demo with the console?
Are you developing a console app, or are you controlling a console app, or maybe both?
Using UnTerminal you can interact with "Powershell" or any other command line process. Check the Example1 on the GitHub.
thanks but this still GUI, my question can I use it for uterminal with my console app?
thanks but this still GUI, my question can I use it for uterminal with my console app?
I think you can use UnTerminal in console Apps, just include the LCL packet dependency, use the "Interfaces" unit, and temporize properly the events:
program project1; uses Interfaces, UnTerminal, SysUtils; type TProc=class proc: TConsoleProc; procedure procLineCompleted(const lin: string); constructor Create; destructor Destroy; override; end; constructor TProc.Create; begin proc := TConsoleProc.Create(nil); proc.LineDelimSend := LDS_CRLF; proc.OnLineCompleted:=@procLineCompleted; end; destructor TProc.Destroy; begin proc.Destroy; end; procedure TProc.procLineCompleted(const lin: string); begin //Line received writeln('--'+lin); //To respond, do something like: proc.SendLn('dir'); end; var p: TProc; i: Integer; begin writeln('Executing process'); p := TProc.Create; p.proc.Open('cmd',''); p.proc.Loop(3); //Execute process until finished or pass 3 seconds p.proc.Close; writeln('Finished'); p.Destroy; end.
This a very basic sample test. Just for test. No interaction, no processing no response. Just opening a CMD command.
thanks but this still GUI, my question can I use it for uterminal with my console app?
I think you can use UnTerminal in console Apps, just include the LCL packet dependency, use the "Interfaces" unit, and temporize properly the events:
program project1; uses Interfaces, UnTerminal, SysUtils; type TProc=class proc: TConsoleProc; procedure procLineCompleted(const lin: string); constructor Create; destructor Destroy; override; end; constructor TProc.Create; begin proc := TConsoleProc.Create(nil); proc.LineDelimSend := LDS_CRLF; proc.OnLineCompleted:=@procLineCompleted; end; destructor TProc.Destroy; begin proc.Destroy; end; procedure TProc.procLineCompleted(const lin: string); begin //Line received writeln('--'+lin); //To respond, do something like: proc.SendLn('dir'); end; var p: TProc; i: Integer; begin writeln('Executing process'); p := TProc.Create; p.proc.Open('cmd',''); p.proc.Loop(3); //Execute process until finished or pass 3 seconds p.proc.Close; writeln('Finished'); p.Destroy; end.
This a very basic sample test. Just for test. No interaction, no processing no response. Just opening a CMD command.
Do you have Powershell in Windows 12 or windows server 2016?
I recommend to test using only the class TProcess to control Powershell in Windows 12 or windows server 2016.
If you success, then test using UnTerminal, because it's just a wrapper for TProcess.
In Windows 10 I can run Powershell without problems.
In Windows 10 I can run Powershell without problems.The command Set-ExecutionPolicy Unrestricted executed,but there is no any output
I can run the PowerShell too, without problem and send commands. Some commands need to start as Administrator. I'm running on Windows 10.0.19044. Unfortunately, I don't have a Windows 7 or some other version of Windows 10 to test .The memo can not display Chinese character properly
The memo can not display Chinese character properly
Hi. I think this is related to this issue: https://github.com/t-edson/UnTerminal/issues/6Yes,it is.