在sandbox中要调用system的工具,用system函数,NSTask方式有的成功,有的不成功。
成功的例子有:
/usr/sbin/screencapture
/usr/bin/stat
不成功的例子有:
/usr/bin/qlmanage
/usr/bin/shasum
/usr/bin/hexdump
/sbin/ping
在网上找到一下答案
Sandbox and running /usr/bin/purge using system()
in an app that is on the Mac App Store, I was doing the following:
system("/usr/bin/nice -n 20 /usr/bin/purge &> /dev/null &");
This worked fine, but now I'm trying to submit a new version, and they're forcing me to enable the Sandbox. However, with the sandbox, that call fails, giving messages like this in the Console:
7/20/13 12:58:59.000 AM kernel[0]: Sandbox: sh(28537) deny file-read-data /dev/ttys000
7/20/13 12:58:59.968 AM purge[28538]: bootstrap_look_up(): Permission denied
7/20/13 12:59:00.000 AM kernel[0]: Sandbox: purge(28538) deny mach-lookup com.apple.appleprofilepolicyd
7/20/13 12:59:00.521 AM purge[28538]: <CPDevice.m:3813> Unable to create new counter client.
7/20/13 12:59:00.523 AM purge[28538]: <CPOSX.m:1188> Unable to get user client so as to poke the kernel.
7/20/13 12:59:00.000 AM kernel[0]: Sandbox: purge(28538) deny iokit-open ApplePerformanceCounterManagerUserClient
7/20/13 12:59:00.000 AM kernel[0]: Sandbox: purge(28538) deny iokit-open AppleProfileUtilitiesUserClient
7/20/13 12:59:00.000 AM kernel[0]: AppleProfileUtilitiesUserClient: bad busy count (0,-1)
7/20/13 12:59:00.000 AM kernel[0]: Backtrace 0xffffff802d22d4d2 0xffffff802d231fc9 0xffffff802ceb3137 0 0 0 0
Is there any way to work around this?