【问题标题】:Can't run curl command from within Elixir with System.cmd无法使用 System.cmd 从 Elixir 中运行 curl 命令
【发布时间】:2016-11-19 23:44:44
【问题描述】:

我只是想用 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

直接从终端运行命令可以正常工作。


这就是我在 Elixir 中尝试做的事情:

args = ["-w config/curl-format.txt", "-o /dev/null", "-s", "http://wordpress.com"]
result = System.cmd("curl", args, [])

但我明白了:

{" config/curl-format.txt", 23}

和上面的结果不一样。

【问题讨论】:

    标签: curl command system elixir


    【解决方案1】:

    您的 System.cmd 调用等效于(在 shell 语法中):

    curl "-w config/curl-format.txt" "-o /dev/null" -s http://wordpress.com
    

    您需要传入-wconfig/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, [])
    

    【讨论】:

    • 感谢呆伯特商人!
    猜你喜欢
    • 2017-09-11
    • 2021-10-26
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    相关资源
    最近更新 更多