有没有办法将参数传递给正在运行的程序:
open -a /Applications/Utilities/Terminal.app ~/my_executable
Run Code Online (Sandbox Code Playgroud)
我试过了:
open -a /Applications/Utilities/Terminal.app ~/my_executable arg1 arg2
Run Code Online (Sandbox Code Playgroud)
但这被解释为告诉终端打开 ~/my_executable ~/arg1 ~/arg2.
我试过了:
open -a /Applications/Utilities/Terminal.app '~/my_executable arg1 arg2'
Run Code Online (Sandbox Code Playgroud)
但是它选择了arg1和arg2,好像它们是路径的一部分而不是参数.
我试过了:
open -a /Applications/Utilities/Terminal.app ~/my_executable | xargs arg1 arg2
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
open -a /Applications/Utilities/Terminal.app ~/my_executable --args arg1 arg2
Run Code Online (Sandbox Code Playgroud)
但是使用那个标志,args被传递到终端.
我只允许将参数更改为Terminal.app([]中的部分):
open -a /Applications/Utilities/Terminal.app [~/my_executable arg1 arg2]
Run Code Online (Sandbox Code Playgroud)
Enr*_*ico 10
您可以通过不带参数的open运行来找到答案:
% open
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]
[...]
--args All remaining arguments are passed in argv to the application's main() function instead of opened.
[...]
您可以看到有一个选项--args
可以像这样使用它:
open ./Untitled.app --args arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)
我在el Capitan(10.11.3)上进行了测试,所以我不知道早期版本中是否存在该选项.
可能最简单的方法是创建一个临时shell脚本,例如
$ echo "~/my_executable arg1 arg2" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; rm /tmp/tmp.sh
Run Code Online (Sandbox Code Playgroud)