Just as an FYI, your newline character on Windows is \n\r. You best to grab
the System.getProperty("line.separator") property for your split.

Other than that I'm not sure I could really think of a better way. This is
where it get's tricky with the "run everywhere" type of thing. Obviously the
best way on the IBM i to run a command would be with the CommandCall class,
but that won't work on Windows.

That being said, if you are already hard-coding something, you might want to
just use the CommandCall instead of the Runtime.getRuntime().exec() method.
Just a thought, not sure on the full scenario so this might not be an option
at all.

James R. Perkins

On Mon, Sep 21, 2009 at 10:54, Lim Hock-Chai

I've solved this with this not so elegant solution: As you can see, I
basically reading the data as ByteArray and does the EBCDIC coversion if
the os.name = OS/400.

private static List<String> readStdio(InputStream is) throws
Exception {

BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
List<String> rs = null;

int result = bis.read();
while(result != -1) {
byte b = (byte)result;
result = bis.read();

String str;
if (System.getProperty("os.name").equals("OS/400"))
str = bao.toString("Cp037");
str = bao.toString();

rs = new ArrayList<String>(Arrays.asList(str.split("\n")));

return rs;

"hockchai Lim" <lim.hock-chai@xxxxxxxxxxxxxxx> wrote in message
I've created a class that will use the Runtime.getRuntime().exec to
a command on iseries when instantiated. Once the command is
executed, it then reads the Process.getInputStream() to get the

I've found that reading of the Process.getInputStream() works fine if
class is instatiated from a PC. However, it failed to read
Process.getInputStream() data correctly when the class is instatiated
iseries. I then added some codes the print the read result in hex and,

appearantly, when the class is instantiate from iseries, the result is
back in EBCDIC encoding format and the BufferedReader is attempting to
it as ASCII. Well, that ain't going to work :(.

Has anyone encountered this problem before? How can I resolve this so
this class can be run on both iseries and PC?

This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.

This thread ...


Return to Archive home page | Return to MIDRANGE.COM home page