www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19275] New: st.process: redirecting output in a non-console


          Issue ID: 19275
           Summary: st.process: redirecting output in a non-console
                    application fails
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

When linking a Windows application with the Microsoft runtime 12 or earlier,
running a process and redirecting its output fails:

import std.process;
import core.sys.windows.windows;

extern(C) int main(string[] args)
                auto res = execute(["dmd.exe", "--version"], null,
                MessageBoxA(null, res.output.ptr, "OK", MB_OK);
        catch(Throwable e)
                MessageBoxA(null, e.msg.ptr, "EXCEPTION", MB_OK);
        return 0;

alias extern(C) int function(string[] args) MainFunc;
extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc);

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
    return _d_run_main(0, null, &main); // arguments unused, retrieved via

causes an exception when built with `dmd -m64 redir.d -L/Subsystem:windows
user32.lib` against VS2013. Works with -m32 or VS2015 and VS2017.

Sep 29 2018