开发者

Calling system() on Jailbroken iPhone

I'm trying to make calls via the C system() function in an application for jailbroken iPhones, but they don't seem to be working. I know it's possible, because the source code for Cydia.app does it, but when I try it, it does nothing.

开发者_JS百科

I set up a simple test, which works fine on the Mac, but comes back empty on device:

system("cd /bin && ls > /tmp/output.txt");
NSLog([NSString stringWithContentsOfFile:@"/tmp/output.txt" usedEncoding:nil error:nil]);

I'm installing this normally, through XCode. I thought I might need to install it in /Applications, but when I try to SSH in and install it in /Applications, it shows up in SpringBoard, but refuses to start.


system("cd /bin && ls > /tmp/output.txt");

Maybe your /bin is just empty, or maybe you don't even have one (I'm not sure what an iPhone's file-system looks like). Try something like echo foo > /tmp/output.txt instead.

That's assuming that /tmp is even writable+existent.

NSLog([NSString stringWithContentsOfFile:@"/tmp/output.txt" usedEncoding:nil error:nil]);

Don't pass random strings to NSLog. Use a format string, even if it's just @"%@", and pass the string object as one of the items to be formatted into it.

Also, you should not pass nil for either of these output parameters. You can pass NULL for the encoding parameter if you really don't care what encoding it is, but you should always pass a pointer to accept an error object, if nothing else so that the framework can tell you why this isn't working (this may be the actual failure point).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜