cmd question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: cmd question

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    97

    cmd question

    EDIT**
    nevermind, i already figured it out


    hey, i was wondering if it is possible from my java program to tell the cmd to execute something like:

    ping www.google.com

    and then have the program "read" from the command prompt. sorry if this is kinda vague, but im not exactly sure how to explain it. if you need a better explaination i can try again =P
    Last edited by anubis; 03-08-2006 at 07:22 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Sydney
    Posts
    49

    HttpURLConnection

    If I have understood you correctly,

    you need to write a simple Java class (say MyURLPing.java) which takes the URL name as the argument from the command line and does a ping using the java library class
    HttpURLConnection.java .

    you run your class as follows:

    Code:
    C:/> java MyURLPing "www.google.com"

    your main class will look something like

    Code:
    public class MyURLPing {
    
           public static void main(String[] args) {
                String url = args[0]; //eg www.google.com
                try {
                     URL u = new URL(url);// 
                     HttpURLConnection huc = (HttpURLConnection) u.openConnection();
                      huc.setRequestMethod("PUT");
                      huc.connect();
                      OutputStream os = huc.getOutputStream();
                      int code = huc.getResponseCode();
                      if (code >= 200 ) { 
                            // put the data...
                       }
                        huc.disconnect();
    }
    catch (IOException e) { //...
    
     
    
           }
    }

    hope this helps.
    Arul

  3. #3
    Join Date
    Dec 2005
    Posts
    97
    ah, ok thats easier then what i was trying to do lol. thanks

Similar Threads

  1. Display one record at a time!
    By ASP learner in forum ASP.NET
    Replies: 5
    Last Post: 10-08-2002, 07:17 PM
  2. Question on asp.net user/server controls
    By Andy Stephens in forum ASP.NET
    Replies: 1
    Last Post: 09-06-2002, 05:29 PM
  3. question on best programming option
    By James in forum .NET
    Replies: 2
    Last Post: 03-28-2002, 07:14 AM
  4. VB,STORED PROC, COM, DTC QUESTION?
    By melvin ng in forum VB Classic
    Replies: 1
    Last Post: 11-10-2000, 03:46 AM
  5. Performance question
    By John in forum VB Classic
    Replies: 2
    Last Post: 04-05-2000, 09:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center