Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

java ping problem

  • 23-03-2006 07:22PM
    #1
    Closed Accounts Posts: 73 ✭✭


    Any one have any idea why this wont work??What its meant to do is put the ping command together and then inserts it into a command window and executes the command.Its putting the ping command together properly but nothing seems to be saving in the textfile "c:\ping.txt".Any help will be greatly appreciated.

    public class Ping{

    Ping(String Ip,String Ip1){
    StringBuffer PingCommand = new StringBuffer("ping -n 1 ");
    String PingText = " > c:\\ping.txt";

    PingCommand.insert(PingCommand.length(),Ip);
    PingCommand.insert(PingCommand.length(),PingText);
    System.out.println(PingCommand);
    try{

    Process PingProcess = Runtime.getRuntime().exec(PingCommand.toString());
    }
    catch(Exception IO){
    }

    }
    public static void main(String[] args){
    Ping p = new Ping("192.168.1.1","");
    }
    }


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    Runtime.getRuntime().exec() does not execute within a command shell like a standard windows cmd.exe. Have a look here on how it should be done


  • Closed Accounts Posts: 73 ✭✭Nocturnal


    ok but i used the exact same thing before except with an nmap command and thats working fine,is there some difference between an nmap command and a ping command exectuting even though ping.exe and nmap.exe both are in the same directory,what i mean is does cmd.exe have to execute before ping.exe executes?


Advertisement