如何将命令行参数传递给使用open命令运行的程序? [英] how to pass command-line arguments to a program run with the open command?

查看:285
本文介绍了如何将命令行参数传递给使用open命令运行的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过以下方式将参数传递给正在运行的程序:

Is there a way to pass arguments to a program being run via:

open -a /Applications/Utilities/Terminal.app ~/my_executable

我尝试过:

open -a /Applications/Utilities/Terminal.app ~/my_executable arg1 arg2

但这被解释为告诉终端打开~/my_executable ~/arg1 ~/arg2.

But this is interpreted as telling the terminal to open ~/my_executable ~/arg1 ~/arg2.

我尝试过:

open -a /Applications/Utilities/Terminal.app '~/my_executable arg1 arg2'

但是它选择了arg1和arg2,就像它们是路径而不是参数的一部分一样.

But it picks up arg1 and arg2 as if they were part of the path rather than arguments.

我尝试过:

open -a /Applications/Utilities/Terminal.app ~/my_executable | xargs arg1 arg2

我也尝试过:

open -a /Applications/Utilities/Terminal.app ~/my_executable --args arg1 arg2

但是带有该标志,args被传递到终端.

But with that flag, args are passed to the terminal.

仅允许将参数更改为Terminal.app([]中的部分):

I am only allowed to change the arguments to Terminal.app (the part within [ ]):

open -a /Applications/Utilities/Terminal.app [~/my_executable arg1 arg2]

推荐答案

最简单的方法可能是创建一个临时的shell脚本,例如

Probably the easiest way is to create a temporary shell script, e.g.

$ echo "~/my_executable arg1 arg2" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; rm /tmp/tmp.sh

这篇关于如何将命令行参数传递给使用open命令运行的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆