从 iPhone 应用程序运行 BASH 脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1039207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:00:54  来源:igfitidea点击:

Running BASH script from iPhone app?

iphonebashscriptingjailbreak

提问by

Basically I am wondering if it is possible to run a console script (.sh) from an iPhone App. The script is written to download a program from a repository that I set up, respring, then after a set time delete the program and respring again, so it needs root privileges, and is interactive in that the user can set how long the program will be kept. I have the bash script written, and it works fine when called from mobile terminal, but is there any way to do this from within a (jailbroken) app (without using mobile terminal / SSH / Bossprefs)? Or is there an overall better way to achieve this? Thanks

基本上我想知道是否可以从 iPhone 应用程序运行控制台脚本 (.sh)。编写脚本是为了从我设置的存储库下载程序,重新启动,然后在设定的时间后删除该程序并再次重新启动,因此它需要 root 权限,并且是交互式的,因为用户可以设置程序运行的时间被保存。我编写了 bash 脚本,从移动终端调用时它工作正常,但是有什么方法可以从(越狱)应用程序中执行此操作(不使用移动终端/SSH/Bossprefs)?或者有没有更好的方法来实现这一目标?谢谢

采纳答案by Johnny Mast

Jasarien is right here it is pretty resticted and as we all know that all apps are sandboxed. But it is not impossible since Objective-C is just build on C you can use

Jasarien 就在这里,它非常受限制,众所周知,所有应用程序都是沙盒的。但这并非不可能,因为 Objective-C 只是建立在您可以使用的 C 上

system("ls");

to execute a basic lscommand and it works if you look in your gdb output. Altho you can also use popen to get the streams to app to work with the data.

执行基本ls命令,如果您查看 gdb 输出,它就可以工作。此外,您还可以使用 popen 将流传输到应用程序以处理数据。

回答by Jasarien

Since you're working with a Jailbroken phone, you're pretty much unrestricted. Whether or not there's anything in the iPhone APIs that allows for script execution is another matter though. Also anything you do use will be unsupported, and is likely to change, stop working or be removed in a software update.

由于您使用的是越狱手机,因此您几乎不受限制。不过,iPhone API 中是否有任何允许脚本执行的内容是另一回事。此外,您使用的任何内容都将不受支持,并且可能会更改、停止工作或在软件更新中被删除。

Also, you probably already know this, or don't care, but you won't get past Apple's review process for the App Store if you start running BASH scripts. Interpreted code is forbidden.

此外,您可能已经知道这一点,或者不在乎,但是如果您开始运行 BASH 脚本,您将无法通过 Apple 对 App Store 的审核流程。禁止解释代码。

回答by Bill K

I would look up how to do it on OSX, chances are that'll be how it's done on the iPhone, but you probably won't find any iPhone specific documentation about it because it's not allowed on a "normal" iphone (one that is not jailbroken)

我会查找如何在 OSX 上执行此操作,很可能就是在 iPhone 上执行此操作的方式,但是您可能找不到任何有关它的 iPhone 特定文档,因为它不允许在“普通”iPhone 上使用(没有越狱)

回答by romejoe

something you may consider is using NSTask if you want to get output and error messages from the shell.

如果您想从 shell 获取输出和错误消息,您可能会考虑使用 NSTask。

回答by Johnny Mast

Actualy

实际上

system('ls /'); gives a better result as system('ls');

system('ls /'); 给出更好的结果作为 system('ls');