Input from named pipe - Forum - OpenEdge Development - Progress Community
 Forum

Input from named pipe

This question is answered

I am trying to read from a named pipe on linux into a longchar.  I first tried the copy-lob, but this didn't work for named pipes.  Then I tried Input From, and the compiler said longchar is an invalid import source.  Is there any way to read directly from a named pipe into a longchar?  If I used input/import and read the named pipe to a char with a repeat statement, will there be any problems if the pipe contains more data than can fit into a regular char?  Are there any best practices for doing this?  I'm using 10.2B008.

Thanks,

Michael

Verified Answer
  • IMPORT with CHARACTER vars is line-oriented. Each IMPORT will stop at the end of a line. If your line is longer than the max size of a CHARACTER, then the IMPORT will fail with a message that might not be obvious, but basically means you have exceeded the size of a variable. Easy enough to test:

    DEFINE VARIABLE cline AS CHARACTER   NO-UNDO.

    OUTPUT TO "longdata.txt".
    PUT UNFORMATTED FILL("x",30000).
    PUT UNFORMATTED FILL("y",2000).
    PUT UNFORMATTED SKIP.
    OUTPUT CLOSE.

    INPUT FROM "longdata.txt".
    IMPORT UNFORMATTED cline.
    INPUT CLOSE.

    As far as I can tell, reading from a named pipe on unix/linux is the same as reading from a file.

All Replies
  • LONGCHARs have a specific IMPORT format. This is why you are getting the "Invalid source for IMPORT of LONGCHAR variable. (14346)" error. If you had the same data in a text file, and tried to read it, I expect you would see the same thing, it is not specific to named pipes.

    I am assuming you are trying to read a stream of unknown length into a LONGCHAR. Is this correct? If so, you might try IMPORTing into RAWs of a determined length then appending to a LONGCHAR. I have not tried this.

  • The only way I've found to read from a named pipe is to define a longchar.  Then I place an import inside a repeat, and read the data into a character variable.  Finally I can append the character data to the longchar var.  The copy-lob only seemed to throw an error when the data was in a named pipe.  I only have some basic text in the pipe.  But if the data is in a file, copy-lob is ok.  Can I be sure that the import statement will not read more data than the character variable can hold?

  • IMPORT with CHARACTER vars is line-oriented. Each IMPORT will stop at the end of a line. If your line is longer than the max size of a CHARACTER, then the IMPORT will fail with a message that might not be obvious, but basically means you have exceeded the size of a variable. Easy enough to test:

    DEFINE VARIABLE cline AS CHARACTER   NO-UNDO.

    OUTPUT TO "longdata.txt".
    PUT UNFORMATTED FILL("x",30000).
    PUT UNFORMATTED FILL("y",2000).
    PUT UNFORMATTED SKIP.
    OUTPUT CLOSE.

    INPUT FROM "longdata.txt".
    IMPORT UNFORMATTED cline.
    INPUT CLOSE.

    As far as I can tell, reading from a named pipe on unix/linux is the same as reading from a file.