Porcelain.spawn does not return status nor writes to stderr
yuraxdrumz opened this issue · comments
Yuri Khomyakov commented
Hey,
I just started using elixir and I love it.
I encountered a problem where I do not have the exit code when executing a shell.
If, for example, I run ipconfig
everything works. If I send a bad command I get an error immediately which is great, but the problem is when I need to get stderr + status code, for exmaple, running ipconfig /notexists
porcelain writes everything to stdout and I do not get the exit code anywhere at all.
Thanks!
def run_cmd(command, args \\ [], opts \\ []) do
combined_opts = [
dir: File.cwd!,
out: :stream,
result: :discard,
err: :stream,
] ++ opts
# spawn process that returns a stream,
# enum each on stream and send it to server for use, send ok after finish
Porcelain.spawn(command, args, combined_opts)
|> case do
{:error, err} -> {:error, err}
%Porcelain.Process{:out => out} ->
Enum.each(out, &stream_to_server/1)
{:ok, ""}
end`
run_cmd("ipconfig", ["/all"]) # works normal
run_cmd("notexists") # works normal
run_cmd("ipconfig", ["notexists"]) # returns std out instead of stderr + status code