2017-09-13 4 views
-1

私は.EXファイルでこのコマンドを実行しようとしている -opensslコマンドを.exファイルで実行する方法は?

私は万能薬で

{_, 0} = System.cmd "openssl", [ "ec", "-in", private_key_file, "-outform", "DER|tail", "-c", "+8|head", "-c", "32|xxd", "-p", "-c", "32"], [stderr_to_stdout: true] 

に翻訳されました

openssl ec -in myprivatekey.pem -outform DER|tail -c +8|head -c 32|xxd -p -c 32 

、が、次のエラーを取得イム - error

このopensslコマンドを正しく実行する方法は?

答えて

2

最初のコードスニペットは、実際には複数のコマンド(openssl、tail、head、xxd)とパイプデータを1つずつ実行しています。 System.cmdは、1つのコマンドだけを生成し、パイプを自動的に処理しません。

あなたはパイプを処理する必要があり、システムのデフォルトのシェルを使用して、コマンドを起動しますこれは、これを実行するために:os.cmd/1を使用することができます。

# Note that this takes the command as a charlist and does not return the exit code 
output = :os.cmd('openssl ec -in myprivatekey.pem -outform DER|tail -c +8|head -c 32|xxd -p -c 32') 

もう一つの方法は、自分がSystem.cmdを使用して、シェルにコマンドを渡すことです。以下は、/bin/shが存在するシステムで動作するはずです:

{stdout, 0} = System.cmd("/bin/sh", ["-c", "openssl ec -in myprivatekey.pem -outform DER|tail -c +8|head -c 32|xxd -p -c 32"]) 
関連する問題