In Erlang, how can I independently capture the stdout and stderr subprocess?

I am trying to figure out how to pull stdout and stderr from a system subprocess in Erlang. (Not to be confused with the Erlang process.) I realized that I was trying to independently output the output of the streams.

open_port / 2 seems to give me most of the way, however it does not seem to make it possible to distinguish between the two threads. There is a stderr_to_stdout option, but this is not what I want; I want to receive data from both data streams, but be able to distinguish between two streams.

Any suggestions? Thanks.

Update: I am ideally looking for a solution that will work on both Windows and Linux.

+5
source share
2 answers

You can try erlexec . As its documentation explains, it allows for separate control over stdout and stderr, and overall it is much more flexible than open_port/2 for controlling OS processes from Erlang.

0
source

Try the following:

 Path = filename:join(["./priv", "log", "log_file_name"]), {ok, F} = file:open(Path, [write]), group_leader(F, self()), erlang:display("Anything this process outputs now gets redirected"). 
0
source

Source: https://habr.com/ru/post/1241163/


All Articles