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

执行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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大