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

Johan Holmberg johan556@REDACTED
Wed May 14 11:01:04 CEST 2008


Hi!

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. I guess this
is quite a typical use of "open_port". I have developed the Erlang
code on Linux, and now when I move it to Windows I get into trouble:

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 think I understand why this happens:

* my application, and the programs it starts are all "console
applications" on Windows

* a console application needs a "console". Either it inherits the one
its parent process uses, or the system will give it a new one.

* in the code for "open_port", Erlang seem to use the flag
"DETACHED_PROCESS" when calling CreateProcess.

* when my application starts other programs, they can't inherit the
console of my application (because of the DETACHED_PROCESS flag used
to start my application)

I have tried to create a minimal example to demonstrate my problem:

    P = open_port({spawn, "env sleep 20"}, [{line, 200}, exit_status]),

Even such a simple call creates a new console (for "sleep 20"). If I
remove the "env" no new console is created.

I guess that the flag DETACHED_PROCESS is used to isolate the process
created by "open_port" from the Erlang Windows-process. But is this
really needed? I think that Erlang would work better together with
console applications if the setting was simply removed.

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?

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

/Johan Holmberg



More information about the erlang-questions mailing list