Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: cmd.exe DOS Window

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default cmd.exe DOS Window

    What is the simplest possible method i could use to write a string to an open cmd.exe DOS Window??

    How would i forward all/read all text appearing in a cmd.exe DOS Window to my java program and recieve every line as a string?

    *If my questions are unclear or more information/detail is required please let me know


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: cmd.exe DOS Window

    Printing text out is easiest done using the System.out stream:

    System.out.println("This is being printed in your command screen");

    To read in text from the console, there are a few different solutions, the easiest being the Scanner object.

    Scanner reader = new Scanner(System.in);
    reader.next(); // reads the next string of characters, ending before a white space.
    reader.nextInt(); // reads the next integer-like string.

    As always, you can use the command prompt's re-direction to send data from/to your java application.

    :java Test >> output.txt

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: cmd.exe DOS Window

    If you wish to grab data from another program running in the cmd window and send data to it, then you will need to call the program through your java application with pipes.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cmd.exe DOS Window

    yeah thats what im looking to do (what freaky chris said), Helloworld922 those first two code boxes are basic input output methods you get taught in school, meaning my question wasnt clear enough, i apologise.

    Chris if you could please explain that in terms of code Id really appreciate it

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: cmd.exe DOS Window

    You can use the same methods when you pipe your input/output from your java program. Piping is the last bit of code I posted (note that that's not actually java code, that's the command you would type into the command prompt). To redirect the command prompt's output to your java program, you would simply switch the order:

    :some_prog.exe >> java my_app

Similar Threads

  1. Unmovable frame (window) -- setFocus
    By chronoz13 in forum AWT / Java Swing
    Replies: 2
    Last Post: December 7th, 2009, 04:00 AM
  2. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 25th, 2009, 09:24 PM
  3. switch focus to another window
    By tuansoibk in forum AWT / Java Swing
    Replies: 1
    Last Post: November 13th, 2009, 02:02 PM
  4. Navigating from one window to another
    By visharaddhavle83 in forum AWT / Java Swing
    Replies: 2
    Last Post: August 6th, 2009, 08:55 AM
  5. I'm not sure how to initialize GraphicsDevice and Window
    By DotChris in forum AWT / Java Swing
    Replies: 3
    Last Post: July 15th, 2009, 10:00 AM