Question Communicating with an external process via INPUT-OUTPUT

Raido Kaju

New Member
I am attempting to use an external process via stdin and stdout to grab a file from a base64 encoded zip file.

The way I am currently going about it is with this code:
Code:
DEFINE STREAM fin.
DEFINE STREAM io.

DEFINE VARIABLE mData AS MEMPTR NO-UNDO.
DEFINE VARIABLE lData AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cLine AS CHARACTER NO-UNDO.
DEFINE VARIABLE cXml AS CHAR INIT '' NO-UNDO.
FILE-INFORMATION:FILE-NAME = 'D:\input.zip'.
SET-SIZE(mData) = FILE-INFORMATION:FILE-SIZE.
INPUT STREAM fin FROM 'D:\input.zip' BINARY NO-MAP NO-CONVERT.
IMPORT STREAM fin mData.
INPUT STREAM fin CLOSE.

INPUT-OUTPUT STREAM io THROUGH VALUE ('gounzip.exe -name K11.txt -b64=true') BUFFER.

lData = BASE64-ENCODE(mData).
PUT STREAM io UNFORMATTED STRING(lData).
OUTPUT STREAM io CLOSE.     
SET STREAM io cLine.
INPUT-OUTPUT STREAM io CLOSE.
SET-SIZE(mData) = 0.

The problem is that the program hangs. If I close the stream with INPUT-OUTPUT STREAM io CLOSE. Then I get a result just fine (checked by logging in the executable) but I cannot read the response.

The same executable works just fine if I use it directly from the command-line and pipe stdin and stdout.

To me the problem seems to be that although I am trying to close the output stream after writing it still keeps it open.

Any advice would be much appreciated.
 
Last edited by a moderator:

GregTomkins

Active Member
What's that 'BUFFER' at the end of the INPUT-OUTPUT statement? At least in 11.2, that's undefined syntax.

Documentation: http://documentation.progress.com/o...href=ABL/ABL Reference/13dvref-IK.027.12.html

This note from the doc could possibly be relevant to your situation:

Be sure that the program you are using does not buffer its output. If the program is a C program, the first line of the program should be “setbuf(stdout, (char *) NULL):”. The program should also include “#include <stdio.h>”. These tell UNIX that the standard output of the program is unbuffered. If the program does buffer its output, use the batch approach to INPUT-OUTPUT THROUGH as explained in the previous note.

I doubt this helps, but I tried this trivial similar (but not identical) example and it worked as expected:

def stream x.
def var y as c.
input-output stream x through value("sort") echo.
put stream x unform "foo\nbar\n".
output stream x close.
repeat:
set stream x y.
disp y.
end.

Result:

y
────
bar
foo
 

Raido Kaju

New Member
Thank you for the reply.

Sorry, buffer was a copy error, it should be unbuffered.

I also forgot to point out that I am using version 10.1c.

As for the code, the input part does not seem to be the issue. Since I also have the source for gounzip.exe I can see that it gets stuck while reading (I can also see that it reads all the data that I send, just never finishes reading unless I close the input-output stream). Everything also seems fine when I pipe the base64 in from a file and just use import through. The issue is though that I need to do this all in memory so writing a temp file would not be an option. Hence the use of input-output through.
 
Top