Computing.Net > Forums > Programming > redirect input : java

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

redirect input : java

Reply to Message Icon

Name: Miskva
Date: April 28, 2003 at 13:02:39 Pacific
OS: w2000
CPU/Ram: -
Comment:

I know, the question is a bit vague .. but I have the following problem

have this DOS .cmf file, which calls some Java code, an this Java code asks some runtime questions .. now, normally, with regular DOS commands, you can always fill in some sort of question file, and then redirect input, like this:

my_program.bat X  my_answers.txt

(the X is the smaller-than sign .. cant get it to display here)

problem now: because of the Java code, it doesnt seem to work ..

he can accept the answers which have a default, but not the ones without ...

anybody ?




Sponsored Link
Ads by Google

Response Number 1
Name: gpp
Date: April 28, 2003 at 13:39:23 Pacific
Reply:

I just ran the following program from the command prompt by directing i.txt into the program and directing the output to o.txt...


import java.io.*;

class Hello {
    public static void main (String args []) {    // main program
        String userName="";
        System.out.print("Enter your name: "); 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        try { 
            userName = br.readLine(); 
        } catch (IOException ioe) { 
            System.out.println("IO error trying to read your name!"); 
            System.exit(1); 
        } 
        System.out.println("Thanks for the name, " + userName); 
    }
}

//Just ran it using this
C:\>java Hello < i.txt > o.txt

i.txt contained a name followed by a newline character.


0
Reply to Message Icon

Related Posts

See More


Setting up an Apache serv... Need Help...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: redirect input : java

Redirect input to a command www.computing.net/answers/programming/redirect-input-to-a-command/17096.html

Further help needed.... www.computing.net/answers/programming/further-help-needed/12646.html

Batch Syntax Help www.computing.net/answers/programming/batch-syntax-help/17431.html