You could skip some of the steps using a InputStreamReader over the
input stream specifying the code page in the constructor.
InputStreamReader is supposed to default to the "platform's default
charset" and may work without having to specify "CP037" explicitly if
the code is running on the '400.

Also, look at some of the JT400 (JTOPEN) IFS classes. The '400 puts
information about the code page of the file in the extended IFS
directory information. I think you have to use the JT400 classes to get
at the information, though.

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Lim Hock-Chai
Sent: Monday, September 21, 2009 12:54 PM
To: java400-l@xxxxxxxxxxxx
Subject: Re: How to resolve the problem with
Runtime.getRuntime().execreturningEBCDIC data when running on iseries

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/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 =;
while(result != -1) {
byte b = (byte)result;
result =;

String str;
if (System.getProperty("").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,
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.