在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:09:52  来源:igfitidea点击:

Executing a bash command in an iOS app

iosbashcommand

提问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?

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

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(). This shows ls being ran in ios simulator.

这个截图显示了 ls 通过 C 函数 system() 在 ios 模拟器中运行。 这表明 ls 正在 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 功能指南