使用System.cmd运行Applescript

时间:2017-09-04 03:20:51

标签: shell elixir phoenix-framework

我有这个功能:

def run(id) do
  {_, status} = System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript"], arg0: id
  {:ok, status}
end

我需要将id传递给osascript。 shell等价物是:osascript ~/lib/script/test.applescript 1但我无法在Elixir中找到正确的选项。无论我做什么,一切都会返回参数错误:

System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript"], arg0: id

System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript"], id

System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript", id]

System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript #{id}"]

如何将id传递给System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript"]

1 个答案:

答案 0 :(得分:2)

似乎它必须是一个字符串才是全部:

{_, status} = System.cmd "osascript", ["#{File.cwd!}/lib/script/test.applescript", "#{id}"]

工作正常。