× 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.



Scott,
I am concerned with the CGI response that is generated for an HTTP request.
If necessary STDIN or QUERY_STRING will already have been processed before
performing the process that generates STDOUT.
I already use QShell on the HTTP server for it's ability to pipe but only
for infrequent requests where the apparent overhead of launching a new
thread each time Qshell is required is tolerable. The solution I have sought
must apply to every cgi request that the server receives so I can't go
wrapping my cgi program (or IBMs DB2WWW) up in a Qshell wrapper.

-----Original Message-----
From: Scott Klement [mailto:klemscot@klements.com]
Sent: Tuesday, April 16, 2002 12:04 PM
To: 'rpg400-l@midrange.com'
Subject: RE: STDIN, STDOUT, STDERR in RPG



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...



_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
or email: RPG400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

This communication is confidential and may be legally privileged. If it is not 
addressed to you, you are on notice of its status. Please immediately contact 
us at our cost and destroy it. Please do not use, disclose, copy, distribute or 
retain any of it without our authority - to do so could be a breach of 
confidence. Thank you for your co-operation. If you need assistance, please 
contact Baycorp Advantage on either :-
Australia 133124 or New Zealand +64 9 356 5800

All personnel email addresses must be in the format 
'firstname.lastname@baycorpadvantage.com'.

* Old Baycorp email addresses will cease to exist after June 1st 2002 *


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.