× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, 16 Apr 2002, Peter Connell wrote:
>
> James, Scott, Jim.
> Thanks. I'm aware that OS like Unix and the C (or C++) language provide an
> operator that permits the output of one program to be easily piped to
> another but the challenge is to prove that this can be achieved effectively
> on OS/400 since the analagous facility to override stdout appears to be
> ignored when the QtmhWrStout Api is used to generate stdout.
>

Again, I'm not familiar with that API or what it does.   But if your goal
is to simply pipe data on the iSeries from one program to another, that
CAN be done...  at least, within QSHELL it can.

> Populating stdout from within an RPGLE cgi program (or C) is a relatively
> simple matter using the built-in Apis or functions that the language
> provides since this is how all CGI programs are written. I suspect that
> James's explanation that stdout does not actually exist as a file may be the
> reason that the concept of subsequently opening it is not possible.
>

Yeah, but I thought you were asking how to read stdin, not stdout...
Where do you get the input data for your CGI script when you use the
POST method?  i.e., if someone passed you a form, where would you get
the data from the web browser?   On Unix systems, you get that from stdin
with the POST method (or from an environment variable with the GET method,
but the env var is limited in size, so we always use POST)


> The piping technique would therefore appear be a mechanism the merely primes
> the OS before making a program call so that it bypasses the usual low level
> process that generates stdout and instead passes the output stream to a
> redirected actual file that is available for read.

Right, if you do redirecting, the shell will open a new STDIN/STDOUT for
you to go to a pipe, or a file, or whatever.   You don't open it yourself
in other environments.

Likewise, if you run your RPG program from QSHELL, you could do the same
thing, since QSHELL opens the pipe/file/whatever for you.

>
> I'm inclined to agree that this cannot be done (unless emulating popen() and
> pclose() is worth a look.)
>

If I understand you correctly, and you just want to pipe the output of
some program to an RPG program for further processing, and you're using
QSHELL, it can be done.   You just use descriptors 0, & 1.

Here's a sample:

      * This rather silly program reads STDIN and translates all of the
      * spaces to periods, then writes it to STDOUT.
      *
      * You need to run this from QSHELL for it to be useful:
      *          /qsys.lib/yourlib.lib/this.pgm

     H BNDDIR('QC2LE') DFTACTGRP(*NO)

     D read            PR            10I 0 extproc('read')
     D  fd                           10I 0 value
     D  buf                            *   value
     D  len                          10I 0 value

     D write           PR            10I 0 extproc('write')
     D  fd                           10I 0 value
     D  buf                            *   value
     D  size                         10I 0 value

     D data            S             80A
     D len             S             10I 0

     c                   eval      len = read(0: %addr(data): %size(data))
     c                   dow       len > 0
     c     ' ':'.'       xlate     data          data
     c                   callp     write(1: %addr(data): len)
     c                   eval      len = read(0: %addr(data): %size(data))
     c                   enddo

     c                   eval      *inlr = *on


To run this, you need to run it from QSHELL.  Here's how I did it:

1) Type STRQSH

2) At the QSHELL prompt, I typed:

echo "I sure wish I had periods in this text!" | /qsys.lib/mylib.lib/test.pgm

(that should all be one line, if it gets wrapped)


And the result looked like this:

   I.sure.wish.I.had.periods.in.this.text!


Hope that helps...





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.