2016-07-17 93 views
0

Ich versuche nur, Elixir zu verwenden, um einen curl-Befehl mit einem bestimmten Format auszuführen.Ich kann den curl-Befehl nicht innerhalb von Elixir mit System.cmd ausführen

$ 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 

Das Ausführen des Befehls direkt vom Terminal funktioniert einwandfrei.


Das ist, was ich versuche in Elixir zu tun:

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

Aber ich bekomme:

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

Und nicht das gleiche Ergebnis wie oben.

Antwort

3

Ihre System.cmd Aufruf entspricht (in Shell-Syntax) zu:

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

Sie müssen config/curl-format.txt, -o in -w, passieren, und /dev/null als unterschiedliche Argumente. Sie haben auch die @ in @config/curl-format.txt verpasst. Dies sollte funktionieren:

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

Vielen Dank based dilbert Händler! –