瀏覽代碼

improved console detection

Unknown 6 年之前
父節點
當前提交
8eca1fb8ee
共有 1 個文件被更改,包括 18 次插入2 次删除
  1. 18 2
      Quick.Commons.pas

+ 18 - 2
Quick.Commons.pas

@@ -7,7 +7,7 @@
   Author      : Kike Pérez
   Version     : 1.7
   Created     : 14/07/2017
-  Modified    : 27/02/2019
+  Modified    : 28/03/2019
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
@@ -191,6 +191,7 @@ type
   function Is64bitOS : Boolean;
   //checks if is a console app
   function IsConsole : Boolean;
+  function HasConsoleOutput : Boolean;
   //checks if compiled in debug mode
   {$ENDIF}
   function IsDebug : Boolean;
@@ -501,6 +502,21 @@ begin
 end;
 {$ENDIF}
 
+function HasConsoleOutput : Boolean;
+{$IFDEF MSWINDOWS}
+  var
+    stout : THandle;
+  begin
+    stout := GetStdHandle(Std_Output_Handle);
+    Win32Check(stout <> Invalid_Handle_Value);
+    Result := stout <> 0;
+  end;
+{$ELSE}
+  begin
+    Result := False;
+  end;
+{$ENDIF}
+
 function IsDebug: Boolean;
 begin
   {$IFDEF DEBUG}
@@ -1320,7 +1336,7 @@ initialization
     begin
       if not IsService then
       begin
-        if IsConsole then Writeln(Format('[WARN] GetEnvironmentPaths: %s',[E.Message]))
+        if HasConsoleOutput then Writeln(Format('[WARN] GetEnvironmentPaths: %s',[E.Message]))
           else raise EEnvironmentPath.Create(Format('Get environment path error: %s',[E.Message]));
       end;
     end;