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.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;
bao.write(b);
result = bis.read();
}
String str;
if (System.getProperty("os.name").equals("OS/400"))
str = bao.toString("Cp037");
else
str = bao.toString();
rs = new ArrayList<String>(Arrays.asList(str.split("\n")));
return rs;
}
"hockchai Lim" <lim.hock-chai@xxxxxxxxxxxxxxx> wrote in message
news:<mailman.3218.1253552449.1811.java400-l@xxxxxxxxxxxx>...
I've created a class that will use the Runtime.getRuntime().exec to
execute
a command on iseries when instantiated. Once the command is
sucessfully
executed, it then reads the Process.getInputStream() to get the
result.
I've found that reading of the Process.getInputStream() works fine if
the
class is instatiated from a PC. However, it failed to read
Process.getInputStream() data correctly when the class is instatiated
from
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
sent
back in EBCDIC encoding format and the BufferedReader is attempting to
read
it as ASCII. Well, that ain't going to work :(.
Has anyone encountered this problem before? How can I resolve this so
that
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.
As an Amazon Associate we earn from qualifying purchases.