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

时间:2022-10-26 16:23:11

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)中执行此操作?或者是否有更好的方法来实现这一目标?谢谢

5 个解决方案

#1


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 ls command 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来获取应用程序流来处理数据。

#2


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的审核流程。禁止使用口译代码。

#3


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上(一个不是越狱了)

#4


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

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

#5


Actualy

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

system('ls /');系统('ls')给出了更好的结果;

#1


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 ls command 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来获取应用程序流来处理数据。

#2


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的审核流程。禁止使用口译代码。

#3


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上(一个不是越狱了)

#4


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

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

#5


Actualy

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

system('ls /');系统('ls')给出了更好的结果;