View Issue Details

IDProjectCategoryView StatusLast Update
0032055FPCLCLpublic2018-11-13 15:15
ReporterYoni StoffmanAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindowsOS10OS VersionCreator Update
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0032055: TProcess doesn't respect the poNoConsole option
DescriptionWhen creating a process with poNoConsole the console screen is still shown.
Steps To Reproducetry
    AProcess := TProcess.Create(nil);
    AProcess.Executable := 'A console app of you liking';
    APRocess.ShowWindow:= TShowWindowOptions.swoHIDE;
    AProcess.Options := AProcess.Options + [poWaitOnExit, poNoConsole,poUsePipes];
    AProcess.Execute;

   finally
     AProcess.Free;
   end;
Additional InformationIt seems that the problem is from a wrong option mapping. The code on process.inc file:

if poNoConsole in FProcessOptions then
      Result:=Result or Detached_Process;

While the documentation on MSDN at https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx

States there that there is an option called CREATE_NO_WINDOW which differ from DETACHED_PROCESS
TagsNo tags attached.
Fixed in Revision36678
FPCOldBugId
FPCTarget
Attached Files
  • TProcess_poNoConsole.32055.patch (2,412 bytes)
    Index: packages/fcl-process/src/win/process.inc
    ===================================================================
    --- packages/fcl-process/src/win/process.inc	(revision 36641)
    +++ packages/fcl-process/src/win/process.inc	(working copy)
    @@ -68,13 +68,13 @@
         begin
         Result:=CREATE_UNICODE_ENVIRONMENT;
         if poNoConsole in Options then
    -      Result:=Result or Detached_Process;
    +      Result:=Result or CREATE_NO_WINDOW;
         if poNewConsole in Options then
    -      Result:=Result or Create_new_console;
    +      Result:=Result or CREATE_NEW_CONSOLE;
         if poNewProcessGroup in Options then
           Result:=Result or CREATE_NEW_PROCESS_GROUP;
         If poRunSuspended in Options Then
    -      Result:=Result or Create_Suspended;
    +      Result:=Result or CREATE_SUSPENDED;
         if poDebugProcess in Options Then
           Result:=Result or DEBUG_PROCESS;
         if poDebugOnlyThisProcess in Options Then
    Index: rtl/win/wininc/defines.inc
    ===================================================================
    --- rtl/win/wininc/defines.inc	(revision 36641)
    +++ rtl/win/wininc/defines.inc	(working copy)
    @@ -646,16 +646,22 @@
          ALTERNATE = 1;
          WINDING = 2;
       { CreateProcess  }
    -     CREATE_DEFAULT_ERROR_MODE = 67108864;
    -     CREATE_NEW_CONSOLE = 16;
    -     CREATE_NEW_PROCESS_GROUP = 512;
    -     CREATE_SEPARATE_WOW_VDM = 2048;
    -     CREATE_SUSPENDED = 4;
    +     CREATE_DEFAULT_ERROR_MODE        = $04000000;
    +     CREATE_NEW_CONSOLE               = $00000010;
    +     CREATE_NEW_PROCESS_GROUP         = $00000200;
    +     CREATE_NO_WINDOW                 = $08000000;
    +     CREATE_PROTECTED_PROCESS         = $00040000;
    +     CREATE_PRESERVE_CODE_AUTHZ_LEVEL = $02000000;
    +     CREATE_SEPARATE_WOW_VDM          = $00000800;
    +     CREATE_SHARED_WOW_VDM            = $00001000;
    +     CREATE_SUSPENDED                 = $00000004;
    +     CREATE_UNICODE_ENVIRONMENT       = $00000400;
    +     EXTENDED_STARTUPINFO_PRESENT     = $00080000;
    +     INHERIT_PARENT_AFFINITY          = $00010000;
    +     DEBUG_PROCESS              = $00000001;
    +     DEBUG_ONLY_THIS_PROCESS    = $00000002;
    +     DETACHED_PROCESS           = $00000008;
          STACK_SIZE_PARAM_IS_A_RESERVATION = $10000;
    -     CREATE_UNICODE_ENVIRONMENT = 1024;
    -     DEBUG_PROCESS = 1;
    -     DEBUG_ONLY_THIS_PROCESS = 2;
    -     DETACHED_PROCESS = 8;
          HIGH_PRIORITY_CLASS = 128;
          IDLE_PRIORITY_CLASS = 64;
          NORMAL_PRIORITY_CLASS = 32;
    
  • TProcess_poNoConsole.32055.v2.patch (2,779 bytes)
    Index: packages/fcl-process/src/win/process.inc
    ===================================================================
    --- packages/fcl-process/src/win/process.inc	(revision 36653)
    +++ packages/fcl-process/src/win/process.inc	(working copy)
    @@ -68,13 +68,13 @@
         begin
         Result:=CREATE_UNICODE_ENVIRONMENT;
         if poNoConsole in Options then
    -      Result:=Result or Detached_Process;
    +      Result:=Result or CREATE_NO_WINDOW;
         if poNewConsole in Options then
    -      Result:=Result or Create_new_console;
    +      Result:=Result or CREATE_NEW_CONSOLE;
         if poNewProcessGroup in Options then
           Result:=Result or CREATE_NEW_PROCESS_GROUP;
         If poRunSuspended in Options Then
    -      Result:=Result or Create_Suspended;
    +      Result:=Result or CREATE_SUSPENDED;
         if poDebugProcess in Options Then
           Result:=Result or DEBUG_PROCESS;
         if poDebugOnlyThisProcess in Options Then
    Index: rtl/win/wininc/defines.inc
    ===================================================================
    --- rtl/win/wininc/defines.inc	(revision 36653)
    +++ rtl/win/wininc/defines.inc	(working copy)
    @@ -646,16 +646,22 @@
          ALTERNATE = 1;
          WINDING = 2;
       { CreateProcess  }
    -     CREATE_DEFAULT_ERROR_MODE = 67108864;
    -     CREATE_NEW_CONSOLE = 16;
    -     CREATE_NEW_PROCESS_GROUP = 512;
    -     CREATE_SEPARATE_WOW_VDM = 2048;
    -     CREATE_SUSPENDED = 4;
    +     CREATE_DEFAULT_ERROR_MODE        = $04000000;
    +     CREATE_NEW_CONSOLE               = $00000010;
    +     CREATE_NEW_PROCESS_GROUP         = $00000200;
    +     CREATE_NO_WINDOW                 = $08000000;
    +     CREATE_PROTECTED_PROCESS         = $00040000;
    +     CREATE_PRESERVE_CODE_AUTHZ_LEVEL = $02000000;
    +     CREATE_SEPARATE_WOW_VDM          = $00000800;
    +     CREATE_SHARED_WOW_VDM            = $00001000;
    +     CREATE_SUSPENDED                 = $00000004;
    +     CREATE_UNICODE_ENVIRONMENT       = $00000400;
    +     EXTENDED_STARTUPINFO_PRESENT     = $00080000;
    +     INHERIT_PARENT_AFFINITY          = $00010000;
    +     DEBUG_PROCESS              = $00000001;
    +     DEBUG_ONLY_THIS_PROCESS    = $00000002;
    +     DETACHED_PROCESS           = $00000008;
          STACK_SIZE_PARAM_IS_A_RESERVATION = $10000;
    -     CREATE_UNICODE_ENVIRONMENT = 1024;
    -     DEBUG_PROCESS = 1;
    -     DEBUG_ONLY_THIS_PROCESS = 2;
    -     DETACHED_PROCESS = 8;
          HIGH_PRIORITY_CLASS = 128;
          IDLE_PRIORITY_CLASS = 64;
          NORMAL_PRIORITY_CLASS = 32;
    Index: rtl/win/wininc/redef.inc
    ===================================================================
    --- rtl/win/wininc/redef.inc	(revision 36653)
    +++ rtl/win/wininc/redef.inc	(working copy)
    @@ -104,7 +104,6 @@
       SIF_TRACKPOS = $10;
       CP_UTF7 = 65000;
       CP_UTF8 = 65001;
    -  CREATE_NO_WINDOW = $08000000;
     
       WHEEL_DELTA = 120;
       WHEEL_PAGESCROLL = MAXDWORD;
    

Activities

Maxim Ganetsky

2017-06-30 13:33

reporter   ~0101388

Last edited: 2017-06-30 13:33

View 2 revisions

This bug seems to belong to FPC project. Moving.

CCRDude

2017-07-06 09:12

reporter   ~0101523

Thanks for filing this bug. I can confirm this, noticed myself a week or two ago, but was too lazy to file a bug here. I'll attach a patch with a fix, plus an update to the CreateProcess consts.

CCRDude

2017-07-06 09:14

reporter  

TProcess_poNoConsole.32055.patch (2,412 bytes)
Index: packages/fcl-process/src/win/process.inc
===================================================================
--- packages/fcl-process/src/win/process.inc	(revision 36641)
+++ packages/fcl-process/src/win/process.inc	(working copy)
@@ -68,13 +68,13 @@
     begin
     Result:=CREATE_UNICODE_ENVIRONMENT;
     if poNoConsole in Options then
-      Result:=Result or Detached_Process;
+      Result:=Result or CREATE_NO_WINDOW;
     if poNewConsole in Options then
-      Result:=Result or Create_new_console;
+      Result:=Result or CREATE_NEW_CONSOLE;
     if poNewProcessGroup in Options then
       Result:=Result or CREATE_NEW_PROCESS_GROUP;
     If poRunSuspended in Options Then
-      Result:=Result or Create_Suspended;
+      Result:=Result or CREATE_SUSPENDED;
     if poDebugProcess in Options Then
       Result:=Result or DEBUG_PROCESS;
     if poDebugOnlyThisProcess in Options Then
Index: rtl/win/wininc/defines.inc
===================================================================
--- rtl/win/wininc/defines.inc	(revision 36641)
+++ rtl/win/wininc/defines.inc	(working copy)
@@ -646,16 +646,22 @@
      ALTERNATE = 1;
      WINDING = 2;
   { CreateProcess  }
-     CREATE_DEFAULT_ERROR_MODE = 67108864;
-     CREATE_NEW_CONSOLE = 16;
-     CREATE_NEW_PROCESS_GROUP = 512;
-     CREATE_SEPARATE_WOW_VDM = 2048;
-     CREATE_SUSPENDED = 4;
+     CREATE_DEFAULT_ERROR_MODE        = $04000000;
+     CREATE_NEW_CONSOLE               = $00000010;
+     CREATE_NEW_PROCESS_GROUP         = $00000200;
+     CREATE_NO_WINDOW                 = $08000000;
+     CREATE_PROTECTED_PROCESS         = $00040000;
+     CREATE_PRESERVE_CODE_AUTHZ_LEVEL = $02000000;
+     CREATE_SEPARATE_WOW_VDM          = $00000800;
+     CREATE_SHARED_WOW_VDM            = $00001000;
+     CREATE_SUSPENDED                 = $00000004;
+     CREATE_UNICODE_ENVIRONMENT       = $00000400;
+     EXTENDED_STARTUPINFO_PRESENT     = $00080000;
+     INHERIT_PARENT_AFFINITY          = $00010000;
+     DEBUG_PROCESS              = $00000001;
+     DEBUG_ONLY_THIS_PROCESS    = $00000002;
+     DETACHED_PROCESS           = $00000008;
      STACK_SIZE_PARAM_IS_A_RESERVATION = $10000;
-     CREATE_UNICODE_ENVIRONMENT = 1024;
-     DEBUG_PROCESS = 1;
-     DEBUG_ONLY_THIS_PROCESS = 2;
-     DETACHED_PROCESS = 8;
      HIGH_PRIORITY_CLASS = 128;
      IDLE_PRIORITY_CLASS = 64;
      NORMAL_PRIORITY_CLASS = 32;

CCRDude

2017-07-06 13:28

reporter  

TProcess_poNoConsole.32055.v2.patch (2,779 bytes)
Index: packages/fcl-process/src/win/process.inc
===================================================================
--- packages/fcl-process/src/win/process.inc	(revision 36653)
+++ packages/fcl-process/src/win/process.inc	(working copy)
@@ -68,13 +68,13 @@
     begin
     Result:=CREATE_UNICODE_ENVIRONMENT;
     if poNoConsole in Options then
-      Result:=Result or Detached_Process;
+      Result:=Result or CREATE_NO_WINDOW;
     if poNewConsole in Options then
-      Result:=Result or Create_new_console;
+      Result:=Result or CREATE_NEW_CONSOLE;
     if poNewProcessGroup in Options then
       Result:=Result or CREATE_NEW_PROCESS_GROUP;
     If poRunSuspended in Options Then
-      Result:=Result or Create_Suspended;
+      Result:=Result or CREATE_SUSPENDED;
     if poDebugProcess in Options Then
       Result:=Result or DEBUG_PROCESS;
     if poDebugOnlyThisProcess in Options Then
Index: rtl/win/wininc/defines.inc
===================================================================
--- rtl/win/wininc/defines.inc	(revision 36653)
+++ rtl/win/wininc/defines.inc	(working copy)
@@ -646,16 +646,22 @@
      ALTERNATE = 1;
      WINDING = 2;
   { CreateProcess  }
-     CREATE_DEFAULT_ERROR_MODE = 67108864;
-     CREATE_NEW_CONSOLE = 16;
-     CREATE_NEW_PROCESS_GROUP = 512;
-     CREATE_SEPARATE_WOW_VDM = 2048;
-     CREATE_SUSPENDED = 4;
+     CREATE_DEFAULT_ERROR_MODE        = $04000000;
+     CREATE_NEW_CONSOLE               = $00000010;
+     CREATE_NEW_PROCESS_GROUP         = $00000200;
+     CREATE_NO_WINDOW                 = $08000000;
+     CREATE_PROTECTED_PROCESS         = $00040000;
+     CREATE_PRESERVE_CODE_AUTHZ_LEVEL = $02000000;
+     CREATE_SEPARATE_WOW_VDM          = $00000800;
+     CREATE_SHARED_WOW_VDM            = $00001000;
+     CREATE_SUSPENDED                 = $00000004;
+     CREATE_UNICODE_ENVIRONMENT       = $00000400;
+     EXTENDED_STARTUPINFO_PRESENT     = $00080000;
+     INHERIT_PARENT_AFFINITY          = $00010000;
+     DEBUG_PROCESS              = $00000001;
+     DEBUG_ONLY_THIS_PROCESS    = $00000002;
+     DETACHED_PROCESS           = $00000008;
      STACK_SIZE_PARAM_IS_A_RESERVATION = $10000;
-     CREATE_UNICODE_ENVIRONMENT = 1024;
-     DEBUG_PROCESS = 1;
-     DEBUG_ONLY_THIS_PROCESS = 2;
-     DETACHED_PROCESS = 8;
      HIGH_PRIORITY_CLASS = 128;
      IDLE_PRIORITY_CLASS = 64;
      NORMAL_PRIORITY_CLASS = 32;
Index: rtl/win/wininc/redef.inc
===================================================================
--- rtl/win/wininc/redef.inc	(revision 36653)
+++ rtl/win/wininc/redef.inc	(working copy)
@@ -104,7 +104,6 @@
   SIF_TRACKPOS = $10;
   CP_UTF7 = 65000;
   CP_UTF8 = 65001;
-  CREATE_NO_WINDOW = $08000000;
 
   WHEEL_DELTA = 120;
   WHEEL_PAGESCROLL = MAXDWORD;

CCRDude

2017-07-06 13:29

reporter   ~0101539

My apologies; one of the consts was accidently declared in a different include file and was a duplicate with my previous patch.

Max Nazhalov

2017-07-06 16:39

reporter   ~0101548

Last edited: 2017-07-06 16:48

View 2 revisions

Side note (some background info): http://github.com/rprichard/win32-console-docs/blob/master/README.md
Not sure blindly discarding DETACHED_PROCESS is the right solution (CREATE_NO_WINDOW is more mild)..

Michael Van Canneyt

2017-07-08 13:37

administrator   ~0101603

Changed the option to CREATE_NO_WINDOW.
Discarded all the other changes.

Please keep your patch to a minimum.

If you do want to move or rename/reformat identifiers, please create
a separate patch and clearly state the reasons why you want to do so.

Please test and close if OK.

Issue History

Date Modified Username Field Change
2017-06-22 20:53 Yoni Stoffman New Issue
2017-06-30 13:33 Maxim Ganetsky Note Added: 0101388
2017-06-30 13:33 Maxim Ganetsky Note Edited: 0101388 View Revisions
2017-06-30 13:33 Maxim Ganetsky Project Lazarus => FPC
2017-07-06 09:12 CCRDude Note Added: 0101523
2017-07-06 09:14 CCRDude File Added: TProcess_poNoConsole.32055.patch
2017-07-06 13:28 CCRDude File Added: TProcess_poNoConsole.32055.v2.patch
2017-07-06 13:29 CCRDude Note Added: 0101539
2017-07-06 16:39 Max Nazhalov Note Added: 0101548
2017-07-06 16:48 Max Nazhalov Note Edited: 0101548 View Revisions
2017-07-08 13:37 Michael Van Canneyt Fixed in Revision => 36678
2017-07-08 13:37 Michael Van Canneyt Note Added: 0101603
2017-07-08 13:37 Michael Van Canneyt Status new => resolved
2017-07-08 13:37 Michael Van Canneyt Fixed in Version => 3.1.1
2017-07-08 13:37 Michael Van Canneyt Resolution open => fixed
2017-07-08 13:37 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-07-08 13:37 Michael Van Canneyt Target Version => 3.2.0