在 iOS 应用程序中执行 bash 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14170416/
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
Executing a bash command in an iOS app
提问by Hang
Is it possible to execute a bash command within an iOS app? For example, I want to execute the "ping" command in my app, and I need to get the command's output as well. Hope I described my question correctly, thank you!
是否可以在 iOS 应用程序中执行 bash 命令?例如,我想在我的应用程序中执行“ping”命令,我还需要获取命令的输出。希望我正确描述了我的问题,谢谢!
采纳答案by Hang
Yes, you can but it is extremely limited, and ping will probably not work... Regardless use the system() and check gdb.
是的,您可以,但它非常有限,并且 ping 可能无法正常工作...无论使用 system() 并检查 gdb。
Running BASH script from iPhone app?
But Quentin is right about using PING.
但是 Quentin 使用 PING 是正确的。
NOTE: This is only useful for debugging and shouldn't be used for actual apps.
注意:这仅对调试有用,不应用于实际应用程序。
This screenshot shows ls being run in the ios simulator through the C function system().

这个截图显示了 ls 通过 C 函数 system() 在 ios 模拟器中运行。

回答by Quentin
Is it possible to execute a bash command within an iOS app?
是否可以在 iOS 应用程序中执行 bash 命令?
As far as I know, bash isn't installed on iOS by default, so you would need to include a copy of bash in your application.
据我所知,默认情况下 bash 未安装在 iOS 上,因此您需要在应用程序中包含 bash 的副本。
For example, I want to execute the "ping" command in my app, and I need to get the command's output as well.
例如,我想在我的应用程序中执行“ping”命令,我还需要获取命令的输出。
pingisn't a bash command. It is a separate application. Apple have a guide to writing ping functionality for iOS.
ping不是bash 命令。它是一个单独的应用程序。Apple有为 iOS 编写 ping 功能的指南。

