f



reading data from a spooled file with java or c (without using the toolkit for java preferably)

hi,

I'm trying to programmatically read (and later analize) data that gets
written to a spooled file.  My approach with java and CL has been to
get the copy the spooled file into an IFS file.  (the way i found to do
something which i think is what i want is to go from spooled file ->
database file -> ifs file (import file?)).  Here are the commands in
CL:  (i'm trying to capture the command for showing jvm jobs but it
could be any other command)

PGM
DSPJVMJOB  OUTPUT(*PRINT)       /* Show jvm jobs. */

CRTPF      FILE(ITESTJ50/DMPJVMDBFL) RCDLEN(132)  /* create
physical/database file*/
MONMSG     MSGID(CPF7302) /* if it exists fine, don't blow up on me */
CPYSPLF    FILE(QPJVADSPJB) TOFILE(ITESTJ50/DMPJVMDBFL) +
             SPLNBR(*LAST)      /* copy last spooled file of this type
to a database member*/
CPYTOIMPF  FROMFILE(ITESTJ50/DMPJVMDBFL) +
             TOSTMF('/home/dmpjvm.txt') MBROPT(*ADD) +

             STMFCODPAG(*STDASCII) RCDDLM(*CRLF) +
             DTAFMT(*FIXED)  /*copy from database file to imported
file?/ifs file? */
SNDPGMMSG  MSG('Done')
ENDPGM

Okay so when i do a wrklnk '/home/dmpjvm.txt' i can see the file just
file.  the ccsid is 437 (Cp437) though and that corresponds to 8-bit
ASCII US PC.

Okay so here is the problem when i look at the file in qsh by doing a
cat '/home/dmpjvm.txt'  i see gibberish.  Also when i try to read the
file in java and convert it to the expected encoding, i only see the
very last line of the file.  Here is the code for that:

 String strFromStdOutFile = "";

        try
        {

            FileReader fr = new FileReader(f);
            int c;

            try
            {
                StringBuffer sb = new StringBuffer();

                while ((c = fr.read()) != -1)
                {
                    sb.append((char)c);
                }

                fr.close();
                strFromStdOutFile = sb.toString();

            }
            catch (IOException e)
            {
                e.printStackTrace();
                System.out.println("IOException: Was not able to read
from the file reader");
            }

        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
            System.out.println("FileNotFoundException: Was not able to
construct a file reader because it could not find the file supplied as
an argument to it");
        }
        System.out.println(strFromStdOutFile);
        String ebstrFromStdOutFile = null;
        try
        {
            ebstrFromStdOutFile= new
String(strFromStdOutFile.getBytes(), "Cp037");
        }
        catch (UnsupportedEncodingException e)
        {

            e.printStackTrace();
        }

        System.out.println("*********************" +"Cp037" );
        System.out.println(ebstrFromStdOutFile);

 String ebstrFromStdOutFile437 = null;
        try {
            ebstrFromStdOutFile437= new
String(strFromStdOutFile.getBytes(), "Cp437");
        } catch (UnsupportedEncodingException e) {

            e.printStackTrace();
        }

        System.out.println("*********---------------************"
+"C437" );
        System.out.println(ebstrFromStdOutFile437);


Anyone know why this is not working for me? i'd be happy with a way to
do what i'm trying to do in C as well.  Finally i'd settle for using
the toolbox for java to do this but i don't know how.

Please help.  Thank you.

My aol screename is amitw1981 is you want to talk about this more.
- Amit

0
3/25/2006 5:29:35 PM
comp.sys.ibm.as400.misc 9219 articles. 4 followers. Post Follow

1 Replies
963 Views

Similar Articles

[PageSpeed] 46

You need to know the CCSID (encoding of the data) created by the 
DSPJVMJOB command.  Most likely it will be in the CCSID of the job 
executing the DSPJVMJOB CL command.

After you copy the spooled file data to the db file, be sure to specify 
the CCSID of the db file that you are copying from.

Make sure you don't run in a server job, or you will run into the 
spooled file being created in a QPRTJOB.  Then your commands won't work 
as you have them currently coded.  If you do end up in this situation, 
use API QSPRILSP to get identity of the spooled file created.

Amit1981 wrote:
> hi,
> 
> I'm trying to programmatically read (and later analize) data that gets
> written to a spooled file.  My approach with java and CL has been to
> get the copy the spooled file into an IFS file.  (the way i found to do
> something which i think is what i want is to go from spooled file ->
> database file -> ifs file (import file?)).  Here are the commands in
> CL:  (i'm trying to capture the command for showing jvm jobs but it
> could be any other command)
> 
> PGM
> DSPJVMJOB  OUTPUT(*PRINT)       /* Show jvm jobs. */
> 
> CRTPF      FILE(ITESTJ50/DMPJVMDBFL) RCDLEN(132)  /* create
> physical/database file*/
> MONMSG     MSGID(CPF7302) /* if it exists fine, don't blow up on me */
> CPYSPLF    FILE(QPJVADSPJB) TOFILE(ITESTJ50/DMPJVMDBFL) +
>              SPLNBR(*LAST)      /* copy last spooled file of this type
> to a database member*/
> CPYTOIMPF  FROMFILE(ITESTJ50/DMPJVMDBFL) +
>              TOSTMF('/home/dmpjvm.txt') MBROPT(*ADD) +
> 
>              STMFCODPAG(*STDASCII) RCDDLM(*CRLF) +
>              DTAFMT(*FIXED)  /*copy from database file to imported
> file?/ifs file? */
> SNDPGMMSG  MSG('Done')
> ENDPGM
> 
> Okay so when i do a wrklnk '/home/dmpjvm.txt' i can see the file just
> file.  the ccsid is 437 (Cp437) though and that corresponds to 8-bit
> ASCII US PC.
> 
> Okay so here is the problem when i look at the file in qsh by doing a
> cat '/home/dmpjvm.txt'  i see gibberish.  Also when i try to read the
> file in java and convert it to the expected encoding, i only see the
> very last line of the file.  Here is the code for that:
> 
>  String strFromStdOutFile = "";
> 
>         try
>         {
> 
>             FileReader fr = new FileReader(f);
>             int c;
> 
>             try
>             {
>                 StringBuffer sb = new StringBuffer();
> 
>                 while ((c = fr.read()) != -1)
>                 {
>                     sb.append((char)c);
>                 }
> 
>                 fr.close();
>                 strFromStdOutFile = sb.toString();
> 
>             }
>             catch (IOException e)
>             {
>                 e.printStackTrace();
>                 System.out.println("IOException: Was not able to read
> from the file reader");
>             }
> 
>         }
>         catch (FileNotFoundException e)
>         {
>             e.printStackTrace();
>             System.out.println("FileNotFoundException: Was not able to
> construct a file reader because it could not find the file supplied as
> an argument to it");
>         }
>         System.out.println(strFromStdOutFile);
>         String ebstrFromStdOutFile = null;
>         try
>         {
>             ebstrFromStdOutFile= new
> String(strFromStdOutFile.getBytes(), "Cp037");
>         }
>         catch (UnsupportedEncodingException e)
>         {
> 
>             e.printStackTrace();
>         }
> 
>         System.out.println("*********************" +"Cp037" );
>         System.out.println(ebstrFromStdOutFile);
> 
>  String ebstrFromStdOutFile437 = null;
>         try {
>             ebstrFromStdOutFile437= new
> String(strFromStdOutFile.getBytes(), "Cp437");
>         } catch (UnsupportedEncodingException e) {
> 
>             e.printStackTrace();
>         }
> 
>         System.out.println("*********---------------************"
> +"C437" );
>         System.out.println(ebstrFromStdOutFile437);
> 
> 
> Anyone know why this is not working for me? i'd be happy with a way to
> do what i'm trying to do in C as well.  Finally i'd settle for using
> the toolbox for java to do this but i don't know how.
> 
> Please help.  Thank you.
> 
> My aol screename is amitw1981 is you want to talk about this more.
> - Amit
> 


-- 
Rodney A Johnson
Technical Team Lead for i5/OS (AS/400) Spool
Dept GJC
IBM   Rochester, Minnesota

The contents of this message express only the sender's opinion.
This message does not necessarily reflect the policy or views of
my employer, IBM.  All responsibility for the statements
made in this Usenet posting resides solely and completely with the
sender.
0
rodjohns (130)
3/27/2006 1:40:46 AM
Reply: