Re: Spam Alert: Passing a value from Unix into 4GL ?
Posted in 2004
You need a C function callable from 4GL. See following code. Regards, Doug Lawry www.douglawry.webhop.org _____________ ___| read_pipe.c |______________________________________________________ /* Run a Unix command and return the first line of output to 4GL Usage: CALL read_pipe(command) RETURNING string Doug Lawry, 19/12/91 */ #include <stdio.h> #define MAX_STRING 512 #define NOTFOUND 100 extern void clip(); extern int status; /* Informix status fiels */ int read_pipe(nargs) int nargs; { FILE *pp; /* pipe pointer */ char cmd[MAX_STRING], /* command to be run */ data[MAX_STRING]; /* return from command */ int bytes = 0; /* number of bytes read */ popquote(cmd, MAX_STRING); /* get the command */ clip(cmd, MAX_STRING); /* strip trailing spaces */ strcat(cmd, " 2>/dev/null"); /* ignore error output */ status = 0; /* set initial status */ if ((pp = popen(cmd, "r")) == NULL) status = NOTFOUND; /* set error status */ else { for (bytes = 0; bytes < MAX_STRING - 1; bytes++) if ((data[bytes] = getc(pp)) == EOF || data[bytes] == '\\n') break; pclose(pp); /* close the pipe */ } data[bytes] = NULL; /* terminate string */ retquote(data); /* return command output */ return(1); /* returning 1 parameter */ } ________ ___| clip.c |___________________________________________________________ /* Subroutine to remove trailing spaces from a string Doug Lawry, 19/10/88 */ void clip(str, len) char *str; int len; { int i; for (i = len - 1; i > 0 && str[i - 1] == ' '; i--); str[i] = NULL; } ________________________________________________________________________ "Francisco Roldan" <f_roldan@admcentralagricola.com.gt> wrote: > Actually , as far as I know it is not possible. > You can simulate it by writing the result in a file or database > and then read it back in 4GL. > > I would love in 4GL the backticks that I can use in Perl and Shell > Script for returning values from system's commands. > To do List in the next 4GL Version ? > > ----- Original Message ----- > From: Dirk Moolman > To: informix-list@iiug.org > Sent: Thursday, May 20, 2004 9:56 AM > Subject: Spam Alert: Passing a value from Unix into 4GL ? > > I am searching the net, but can't find an answer yet. > > How can I run a 4GL, that will run a Unix command, and then keep > the result of the Unix command in a variable in the 4GL ? > > Example: > > Let's say I have a script that does a word count (wc) on a file. > I want to run this script from a 4GL program, and then use the result > of the word count in the 4GL. > > Should be simple, but I don't know how ...