views:

2020

answers:

6

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

A: 

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.

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.

Jasarien
+1  A: 

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)

Bill K
Bill said it pretty well. This is exactly the sort of unrestricted OS access that Apple works to prevent by sandboxing apps in the iPhone OS. Should be possible on a jailbroken one, though - don't see why not.
Ben Gotow
A: 

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

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.

Johnny Mast
Thanks alot everyone...I think I'm going to try to use the system() and/or popen() commands to do this. From what i've read that is generally how this is done from objective C
A: 

Actualy

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

Johnny Mast
A: 

That is great :) Then you can declare this question as closed by pressig the V mark on the left on my answer. Have fun :)

Johnny Mast
A: 

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

romejoe