在iOS上使用带有参数的Xcode运行Shell脚本 [英] Running shell script using Xcode with arguments on ios

查看:167
本文介绍了在iOS上使用带有参数的Xcode运行Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,我想从应用程序的参数开始. 目前,我可以生成命令,但是如何执行呢? 这个程序只适用于越狱的手机. 有什么解决办法吗?我搜索了很多,但没有找到任何东西.

I have a bash script which I want to start with arguments by an app. Currently I can generate the command, but how can I execute it? This app is for jailbroken phones only. Any solutions for this? I searched a lot, but didn't found anything.

推荐答案

如果这是一个越狱应用程序,则可以通过将命令传递给system()

If this is a jailbreak app, you can run the command by passing it to the system() function that's part of the OS, or one of the exec functions.

因此,如果您决定将脚本安装在/Applications/MyApp.app/myscript.sh上,则可以在您的应用中使用:

So, if you decide to install your script at /Applications/MyApp.app/myscript.sh, then in your app, you could use:

int result = system("/Applications/MyApp.app/myscript.sh argument1 argument2");

您可以按照我的说明将脚本安装在应用程序的文件夹中,作为资源或安装在/usr/bin/bin或任何您喜欢的位置.

You can install the script as I've shown, in your app's folder, as a resource, or in /usr/bin, or /bin, or wherever you like.

您没有提及是否要像大多数越狱应用程序一样在/Applications中或正常的/var/mobile/Applications/*位置中安装应用程序.

You don't mention whether or not you're installing your app in /Applications, as most jailbreak apps are, or in the normal /var/mobile/Applications/* locations.

如果上面的代码不起作用,请在位置中阐明您要安装应用程序的位置.另外,根据您的脚本是否需要root特权,可能还需要做更多的工作.如果您想以root用户身份运行Shell脚本,则有一些复杂情况.

If the above code doesn't work, please clarify where you want to install your app. Also, depending on whether or not your script requires root privileges, there may be more work necessary. There are some complications if you want to run a shell script as root.

这篇关于在iOS上使用带有参数的Xcode运行Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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