You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
program DosCommandTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
LoggerPro,
LoggerPro.ConsoleAppender;
const c_defTAG = 'Test';
var
Log: ILogWriter;
begin
try
for var i := 1 to 10 do
Writeln('Console message ' + i.ToString);
Log := BuildLogWriter([TLoggerProConsoleAppender.Create]);
for var i := 1 to 10 do
begin
Log.Debug('Log message ' + i.ToString(), c_defTAG);
Log.Info('Log message ' + i.ToString(), c_defTAG);
Log.Warn('Log message ' + i.ToString(), c_defTAG);
Log.Error('Log message ' + i.ToString(), c_defTAG);
end;
Sleep(20000);
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Test App code;
unit ConsoleLogMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DosCommand, Vcl.StdCtrls;
type
TForm8 = class(TForm)
Memo1: TMemo;
Button1: TButton;
DosCommand1: TDosCommand;
procedure Button1Click(Sender: TObject);
procedure DosCommand1NewLine(ASender: TObject; const ANewLine: string;
AOutputType: TOutputType);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form8: TForm8;
implementation
{$R *.dfm}
procedure TForm8.Button1Click(Sender: TObject);
begin
DosCommand1.CommandLine := ExtractFilePath(Application.ExeName) + 'DoscommandTest.exe';
DosCommand1.CurrentDir := ExtractFilePath(Application.ExeName);
Memo1.Lines.Clear;
DosCommand1.Execute;
end;
procedure TForm8.DosCommand1NewLine(ASender: TObject; const ANewLine: string;
AOutputType: TOutputType);
begin
if AOutputType = otEntireLine then
begin
Memo1.Lines.Add(ANewLine);
end;
end;
end.
The text was updated successfully, but these errors were encountered:
The TDosCommand component runs your application within a thread. It calls the main thread with Queue. If the main thread has time, it iterates the queue.
I just tested your example, without the LoggerPro component, and everything is fine.
In a real application you can consider to call CheckSynchronize within your main thread if it is idle.
I made a sample console application which writes some console messages with WriteLn and with LoggerPro library
There is missing lines on output strings when ecexuted with DosCommand.
Output is ;
But OnNewLine event getting only,
Test projects is on the attachment.
TestDosCommand.zip
Console App code ;
Test App code;
The text was updated successfully, but these errors were encountered: