Ser*_*pia 0 curl command system elixir
我只是尝试使用 Elixir 运行特定格式的curl 命令。
$ curl -w "@config/curl-format.txt" -o /dev/null -s "http://wordpress.com/"
0.004, 0.017, 0.000, 0.017, 0.000, 0.029, 0.029
Run Code Online (Sandbox Code Playgroud)
直接从终端运行命令效果很好。
这就是我在 Elixir 中尝试做的事情:
args = ["-w config/curl-format.txt", "-o /dev/null", "-s", "http://wordpress.com"]
result = System.cmd("curl", args, [])
Run Code Online (Sandbox Code Playgroud)
但我得到:
{" config/curl-format.txt", 23}
Run Code Online (Sandbox Code Playgroud)
而且结果和上面不一样。
您的System.cmd调用相当于(在 shell 语法中):
curl "-w config/curl-format.txt" "-o /dev/null" -s http://wordpress.com
Run Code Online (Sandbox Code Playgroud)
您需要传入-w、config/curl-format.txt、-o和/dev/null作为不同的参数。你也错过@了@config/curl-format.txt。这应该有效:
args = ["-w", "@config/curl-format.txt", "-o", "/dev/null", "-s", "http://wordpress.com"]
result = System.cmd("curl", args, [])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
696 次 |
| 最近记录: |