System.cmd suppresses output in Elixir

I create an RSA key pair using the openssl command line on Elixir and everything works, except that I could not suppress the output of this command.

This is what I run:

{_, 0} = System.cmd "openssl", [ "genrsa", "-out", "privateKey.pem", "2048"] 

and I keep getting:

 Generating RSA private key, 2048 bit long modulus .....+++ .....................................+++ e is 65537 (0x10001) 

After compiling with escript and running the executable.

+5
source share
1 answer

System.cmd collects the standard output from the command and returns it, but here it happens that OpenSSL writes a standard error, which by default is not fixed and, therefore, is simply printed on the terminal.

You can use the stderr_to_stdout option:

 iex(2)> {_, 0} = System.cmd "openssl", [ "genrsa", "-out", "key.pem", "2048"], [stderr_to_stdout: true] {"Generating RSA private key, 2048 bit long modulus\n.......................+++\n......................................+++\ne is 65537 (0x10001)\n", 0} 

This means that the output will be returned in the first element of the tuple instead of typing on the terminal. Since you ignore this part of the return value, it will not be displayed when your program starts.

+8
source

All Articles