douyi8732 2013-10-05 00:33
浏览 37

执行Windows命令行命令

Here is an overview of what I am doing. I have a Java Swing application. On it I have a button called 'Ping'. What I want to happen is that when I click on the button Ping then it should ping a particular server. The server IPAddress details are in a text box.

So this is the code I have.

try {
    Process p = Runtime.getRuntime().exec(strbf.toString());

    if (Action.equalsIgnoreCase("PING"))
    {
           BufferedReader in = new BufferedReader(  
                   new InputStreamReader(p.getInputStream()));  
           String line = null;  
           while ((line = in.readLine()) != null) 
           {  
              mylogger.logInfo("Servers", "actionToBeTaken", "Ping line is" + line);
           }
    }  

So the output of the ping goes into a logger file. Everything is good so far. But I don't want this behavior. Note that if I type in ping into the windows run prompt or dos prompt then a seperate ping window pops up. This is the way I want my code to function. Click on a button and the window automatically pops up. What changes do I make to my code? I tried different things but it does not seem to work. For example the below does not work. I don't know where the output of the ping command is getting eaten up. How do I ensure the command prompt windows pops up and the ping output is visible there.

try {
    if (Action.equalsIgnoreCase("PING"))
    {
         Runtime.getRuntime().exec(strbf.toString());
    }  
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能