Consultor Eletrônico



Kbase 20588: Sample 4GL Code Using INPUT-OUTPUT THROUGH to a C Program
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

How to communicate with an OS executable written in C language

FACT(s) (Environment):

How to communicate using pipes
Using INPUT-OUTPUT THROUGH statement
Progress 4GL

FIX:

Sometimes you might need to access data or functions available to a C program or operating system program. This solution provides example code to do it.

There are various methods to make Progress communicate with a C program. Depending on the operating system platform (MS-Windows or UNIX), the following methods can be used:
- COM Objects.
- ActiveX.
- MS-Windows Dynamic Data Exchange.
- MS-Windows Dynamic Link Libraries (DLL).
- Name Pipes.
- Pipes.
- Sockets.
- The Host Language Call interface (HLC).
- UNIX shared libraries.


The 4GL statements used for input, SET, IMPORT, follow the same
rules as those used with regular input (from a file or from the terminal).

These input statements expect a newline (\n) character at
the end of each input line. The C program should generate a
newline character for each input line, otherwise, the 4GL
program will be waiting indefinitely.

For data sent from the C program that is separated by spaces,
the SET and IMPORT statements can either use multiple fields
to read each piece of the C data or use IMPORT UNFORMATTED.

For example:
- SET field1 field2 field3.
- IMPORT field1 field2 field3.
- IMPORT UNFORMATTED field.

The following sample 4GL program communicates with a C progrm:

DEF VAR X AS CHAR FORMAT "X(30)".
DEF VAR Y AS CHAR FORMAT "X(30)".
DEF STREAM io.

X = "none".
INPUT-OUTPUT STREAM io THROUGH "pipe1" UNBUFFERED.
REPEAT:
UPDATE X.
PUT STREAM io X SKIP.
SET STREAM io Y.
DISPLAY Y.
END.
INPUT-OUTPUT STREAM io CLOSE.


The following sample C program can be used from a 4GL program:

#include <stdio.h>
#include <string.h>

int main()
{
int c;
char buff[255];

setbuf(stdin, (char *) NULL);
setbuf(stdout, (char *) NULL);
while (fscanf(stdin, "%s", &buff)){
fprintf(stdout, "Data-%s\n", strupr(buff));
if (stricmp(buff, "<END>") == 0) break;
}
return 1;
}