【发布时间】:2018-06-22 11:46:38
【问题描述】:
有没有办法将参数传递给正在运行的程序:
open -a /Applications/Utilities/Terminal.app ~/my_executable
我试过了:
open -a /Applications/Utilities/Terminal.app ~/my_executable arg1 arg2
但这被解释为告诉终端打开~/my_executable ~/arg1 ~/arg2.
我试过了:
open -a /Applications/Utilities/Terminal.app '~/my_executable arg1 arg2'
但它会拾取 arg1 和 arg2,就好像它们是路径的一部分而不是参数一样。
我试过了:
open -a /Applications/Utilities/Terminal.app ~/my_executable | xargs arg1 arg2
我也试过了:
open -a /Applications/Utilities/Terminal.app ~/my_executable --args arg1 arg2
但是有了那个标志,args 被传递到终端。
注意
我只允许将参数更改为 Terminal.app([ ] 内的部分):
open -a /Applications/Utilities/Terminal.app [~/my_executable arg1 arg2]
【问题讨论】:
-
是否有理由不使用
open命令直接运行可执行文件? -
是的,因为这是 Xcode 使用的命令:/Trying to pass arguments to a program that uses ncurses(因此必须在终端窗口中调试)。
-
你尝试将 --args 放在你的 ecexutable 前面:
open -a /Applications/Utilities/Terminal.app --args ~/my_executable arg1 arg2? -
这也不行,@chown。您可以通过打开终端并输入此命令自己尝试。
open -n -a /Applications/Utilities/Terminal.app --args ~/my_executable arg1 arg2