Java BufferedReader openvms

254 views Asked by At

I'm a JAVA newbie and developing my first program. I'm using Eclipse Luna on a Windows 7 PC. The version of JAVA I'm compiling to is 1.4.2 as that is the version of the JAVA on the target system which I am unable to change. The target system is running HP OpenVMS.

On the PC I'm just trying to get an input string from the keyboard, then print it out. It works fine on the PC. I then Export -> Runnable JAR to the OpenVMS box and run it there. When I do that I get the Enter Input String: prompt. Without me touching the keyboard this then quickly changes to Enter Input String: String is null and the program just ends at that point. Code is shown below. Can someone tell me what I'm doing wrong?

JAVA Code

package test;

import java.io.BufferedReader;                                             
import java.io.IOException;                                                
import java.io.InputStreamReader;                                          

public class test {

    public static void main(String[] args) throws IOException {          

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Enter input string: ");           
        String s = br.readLine();           
        System.out.println("String is " + s);           
    }   
}

On the openVMS box I'm running this command file

$ set file/attr=(rfm:stmlf,rat:cr) xx2.jar                                       
$ java -cp xx2.jar test.test

And the output of this looks like

$ @test                                                                         
$ Enter input string: String is null
1

There are 1 answers

1
user2116290 On BEST ANSWER

You are running a DCL script, aka a command procedure. That is, the input is redirected to your command file. It looks like the Java command is the last line in the command file, so readLine() gets EOF.

Try to execute the Java command from the DCL command line or change your command procedure to

$ set file/attr=(rfm:stmlf,rat:cr) xx2.jar                                     
$ define/user sys$input sys$command                                             
$ java -cp xx2.jar test.test

This redirects the input to the source from which you started the command procedure, usually your terminal.