Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #859 (closed defect: fixed)

Opened 8 months ago

Last modified 7 months ago

Process creates detached processes

Reported by: schveiguy Assigned to: schveiguy
Priority: normal Milestone: 0.99.5
Component: Core Functionality Version: trunk
Keywords: win32 Cc:

Description (Last modified by schveiguy)

On windows, Process creates processes with the DETACHED_PROCESS flag. This causes problems when you run processes through batch files that expect a console window.

What I think happens is cmd.exe realizes it needs a console window, creates its own, and then redirects stdout/err to that console instead of reading/writing to the pipes.

For example, The following code demonstrates:

import tango.sys.Process;
import tango.io.Stdout;


int main(char[][] args)
{
  Process p = new Process("cmd.exe /c \"diskpart.exe /?\"", null);
  p.execute();
  auto pr = p.wait();
  Stdout("stdout:").newline;
  Stdout.conduit.copy(p.stdout);
  Stdout("\nstderr:").newline;
  Stdout.conduit.copy(p.stderr);
  Stdout("\nreturned return code of ", pr.status).newline;
  return 0;
}

The cmd /c diskpart simulates a batch file (don't worry, diskpart /? won't hose your machine). The same thing happens if "diskpart /?" is in a batchfile that you run.

Here is the output with the current library (note that a console window flashes to run diskpart in):

stdout:

stderr:

returned return code of , 0

If I remove DETACHED_PROCESS from the CreateProcess call, the stdout and stderr is properly redirected to the pipes:

stdout:

Microsoft DiskPart version 5.1.3565

Copyright (C) 1999-2003 Microsoft Corporation.
On computer: STEVES

Microsoft DiskPart syntax:
        diskpart [/s <script>] [/?]

        /s <script> - Use a DiskPart script.
        /?          - Show this help screen.

stderr:

returned return code of , 0

Change History

01/18/08 15:58:29 changed by larsivi

  • keywords set to win32.
  • milestone set to 0.99.5.

02/13/08 09:49:28 changed by schveiguy

  • owner changed from jcomellas to schveiguy.
  • status changed from new to assigned.
  • description changed.

02/13/08 10:10:00 changed by schveiguy

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in changeset [3178]