Running shell script using Xcode with arguments on ios

依然范特西╮ 提交于 2019-12-08 09:10:31

问题


I have an bash script which I wan't 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? searched alot, but didn't found anything.


回答1:


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.

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");

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.

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.

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.



来源:https://stackoverflow.com/questions/14429426/running-shell-script-using-xcode-with-arguments-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!