Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Calling a C program from CL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling a C program from CL

    I'd have to see the C program in more detail to help out definitively, but what happens if you set the lengths of the two variables to 40? By setting them shorter than 40, you're messing with the C program's storage. Converting calls with parameters from the command line to CL is always a little tricky; the command line does some strange default behaviors (for example, it pads character fields to 32 bytes, and it stuffs numeric fields in 15.5 packed fields). The best way is to be very careful that the parameters in your CL program exactly match the parameters in the called program. Joe

  • #2
    Calling a C program from CL

    I believe a null terminated string just has a X'00' at the end of the string... Chris

    Comment


    • #3
      Calling a C program from CL

      That is what I have always used in RPG programs and I tried using it in the CL program like this - CHGVAR VAR(&FILE_IN) VALUE'/CHILDRENS/HSFSCHD_F20.RTF'||X'00') and CL did not like it. After reading your post, I took another approach and did the following - DCL VAR(&NULL) TYPE(*CHAR) LEN(1) VALUE(X'00') CHGVAR VAR(&FILE_IN) VALUE'/CHILDRENS/HSFSCHD_F20.RTF'||&null) and it worked like a charm! Thanks, Joe

      Comment


      • #4
        Calling a C program from CL

        Thanks for the reply Joe. I was just about to post the source when I tried to null terminate the string a different way (see other post) and it worked! Thanks, Joe

        Comment


        • #5
          Calling a C program from CL

          Way cool! It's good to know that C likes null-termination (which makes sense). I guess the command line magically null-terminates the strings when it passes them! Joe

          Comment


          • #6
            Calling a C program from CL

            The var in CL must have the length declared in PARM of the program you call. Calling a RPG from CL has the same prerequisite, this is not C related. Try to create a RPG program with a 1024 char param, then call it from CL with a 10 char param in debug mode, and display the param in RPG: you will see the 10 char passed and then lot of strange stuff. Conclusion: carefully use the correct length in CL var to call programs. Fred

            Comment


            • #7
              Calling a C program from CL

              We have a C program named RTFREADR that takes an RTF file from the IFS and converts it to TXT. We have used this program for years and run it from an RPG program using QCMDEXEC and have never had any trouble. I now want to run it from a CL and am having parameter problems. I have attached a sample CL that illustrates the problem. The C progam returns this message - Can't open input file: /CHILDRENS/HSFSCHD_F20.RTF/CHILDRENS/HSFSCHD_F20/CHILD RENS/HSFSCHD_F20.RTF.TXT Press ENTER to end terminal session. Note that the two parameters seem to be run together. I wonder if the parameters should be null terminated? If so, how do you null terminate a string in CL? Any and all thoughts and suggestions are most welcome! Thanks, Joe
              Code

              Comment


              • #8
                Calling a C program from CL

                I seem to remember having this problem a few times in CL/CLLE programs and by initializing VALUE(' ') - one blank for character (no matter what the size), or 0 for numeric when the variable is declared (or using CHGVAR if necessary) - all the buffer gunk is flushed. In RPGLE pgms, I believe using OPDESC is always necessary for C procedure calls. In CL you must do your own legwork.

                Comment


                • #9
                  Calling a C program from CL

                  bobtheplanet wrote: > I seem to remember having this problem a few times in CL/CLLE > programs and by initializing VALUE(' ') - one blank for character (no > matter what the size), or 0 for numeric when the variable is declared > (or using CHGVAR if necessary) - all the buffer gunk is flushed. In > RPGLE pgms, I believe using OPDESC is always necessary for C > procedure calls. In CL you must do your own legwork. OPDESC is rarely needed when calling C. It is only needed if the C procedure is defined with #pragma descriptor.

                  Comment

                  Working...
                  X