从应用程序中的shell中运行ping命令 [英] Running ping command in the shell from app

查看:436
本文介绍了从应用程序中的shell中运行ping命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到源$ C ​​$ C,它提供了一个机会来运行应用程序shell命令,并且,我能理解,会返回一个字符串,执行的命令的结果:

I have found source code that gives an opportunity to run a shell command from the app, and, as I can understand, returns a string with the executed command result:

<一个href="http://$c$c.google.com/p/netmeterled/source/browse/trunk/src/com/britoso/cpustatusled/utilclasses/ShellCommand.java?r=29" rel="nofollow">http://$c$c.google.com/p/netmeterled/source/browse/trunk/src/com/britoso/cpustatusled/utilclasses/ShellCommand.java?r=29

我曾尝试实行平-c 3 www.google.com,但给定的方法返回错误:空。我执行命令的方式是:

I have tried to execute "ping -c 3 www.google.com", but the given method returns "Error: null". The way I execute the command is:

ShellCommand cmd = new ShellCommand();
CommandResult r = cmd.sh.runWaitFor("ping -c 5 www.google.com");
String text;
if (!r.success()) {
    text = "Error:\n" + r.stderr;
}
else {
    text ="Ping test results:\n" + r.stdout;
}
log(text);

问题出在哪里?

Where is the problem?

推荐答案

你有没有上网权限的应用程序?并连接到互联网的设备?有没有在logcat的任何输出?

Do you have Internet permission for your app? And is the device connected to the Internet? Is there any output in the Logcat?

这个问题显示了一种方法,你可以使用从Java到平,而无需运行shell命令。

This question shows a one method you could use to ping from Java, without needing to run the shell command.

这篇关于从应用程序中的shell中运行ping命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆