[erlang-questions] "open_port" problem on Windows (DETACHED_PROCESS)

Johan Holmberg <>
Wed May 21 21:01:42 CEST 2008

On Wed, May 14, 2008 at 11:01 AM, Johan Holmberg <> wrote:
> I'm trying to use Erlang to run/control an existing application. I use
> "open_port" to start the application, and communicate by
> reading/writing to the STDIN/STDOUT of the application.
> My application starts other processes (compilers, linkers, ...), and
> *each invocation* of these creates a new console window. So I get
> hundreds of console windows that only exist for a short time.
> I would appreciate any hints about what to do to avoid all the extra
> consoles. Maybe I have missed some way of affecting how "open_port"
> works?

Richard Carlsson showed me an undocumented option to "open_port"
called "hide". Setting this option causes CreateProcess to be called
with the SW_HIDE flag. With this option, I don't see all the windows
any more. But I guess they are still created by Windows, just not

> (Currently I'm considering trying to build Erlang myself, and change
> the CreateProcess call to not use DETACHED_PROCESS).

I actually did build Erlang from source too, to be able to experiment
with running Erlang without the DETACHED_PROCESS option. I added an
option {detached, true/false} to "open_port", so I could choose at
runtime if I wanted the DETACHED_PROCESS option or not.

Currently I use {detached, false} when running my application. My gut
feeling is that this is better than using the "hide" option when
running "erl" in a console. It seems wrong to me that a console
application should be forced to deal with "windows stuff"

 /Johan Holmberg

More information about the erlang-questions mailing list