|
On Sat, 6 Apr 2002, Scott Klement wrote:
>
> Most likely (since touch works in my example) it's complaining about
> not having the stdin, stdout, and stderr streams already open for it.
> Usually, the STRQSH would do this... but, if you're doing it from an
> RPG program, you'll need to open them manually.
>
> I'll dig up your example and see if I can get it to work on my system.
>
Yes, it appears that I was on target -- opening up descriptors for stdin,
stdout and stderr enabled your example to work. I had to fill in a lot
of the blanks, since your sample code wasn't a full program (just a
snippet) so here's the program, along with everything that I did to it.
This code works on my system, I guess there might be some other difference
between our systems that's still causing problems, but it's the only place
I have to test things right now.
Here it is:
H DFTACTGRP(*NO) BNDDIR('QC2LE')
** Added OPTIONS(*STRING) to one of your 3 sample prototypes:
DQzshSystemAPI PR 10I 0 EXTPROC('QzshSystem')
D PR_Cmd * VALUE OPTIONS(*STRING)
C* Added all of this code:
C*---------------------------------------------------------
D SndUnixErr PR 1N
D peMsgTxt 256A const
D SDS
D dsJobNo 264 269A
D SetupIO PR 80A
D CloseIO PR
D cmd S 100A
D RtnCod S 10I 0
D RtnErr S 1N inz(*OFF)
D msg s 80A
c eval cmd = 'touch -C 00817 /tmp/test.txt'
c eval msg = SetupIO
c if msg <> *blanks
c callp SndUnixErr(msg)
c endif
C*---------------------------------------------------------
* This is what's left of your code (sorry, but just adding
* options(*string) eliminated a lot of it)
c EVAL RtnCod = QzshSystemAPI(%trimr(cmd))
C IF RtnCod <> *ZEROS
c callp CloseIO
C CALLP SndUnixErr('Error in Qsh Command: ' +
C %TRIM(Cmd))
C EVAL RtnErr = *ON
C ENDIF
* Added all of this code:
*---------------------------------------------------------
c callp CloseIO
C EVAL *INLR = *ON
**
** Since you didn't explain what SndUnixErr did, I created
** this procedure, to fill in that part of the code:
**
P SndUnixErr B export
D SndUnixErr PI 1N
D peMsgTxt 256A const
D SndPgmMsg PR ExtPgm('QMHSNDPM')
D MessageID 7A Const
D QualMsgF 20A Const
D MsgData 256A Const
D MsgDtaLen 10I 0 Const
D MsgType 10A Const
D CallStkEnt 10A Const
D CallStkCnt 10I 0 Const
D MessageKey 4A
D ErrorCode 1A
D dsEC DS
D dsECBytesP 1 4I 0 inz(256)
D dsECBytesA 5 8I 0 inz(0)
D dsECMsgID 9 15
D dsECReserv 16 16
D dsECMsgDta 17 256
D wwMsgLen S 10I 0
D wwTheKey S 4A
c eval wwMsgLen = %len(%trimr(peMsgTxt))
c if wwMsgLen<1
c return *off
c endif
c callp SndPgmMsg('CPF9897': 'QCPFMSG *LIBL':
c peMsgTxt: wwMsgLen: '*ESCAPE':
c '*': 3: wwTheKey: dsEC)
c return *off
P E
*===============================================================
* File descriptors 0, 1 & 2 are used by unix-environments for
* stdin, stdout & stderr.
*
* Here we just direct those 3 descriptors to stream files
*===============================================================
P SetupIO B
D SetupIO PI 80A
** IFS APIs used for simulating STDIN, STDOUT, STDERR
D open PR 10I 0 ExtProc('open')
D filename * value options(*string)
D openflags 10I 0 value
D mode 10U 0 value options(*nopass)
D codepage 10U 0 value options(*nopass)
D close PR 10I 0 ExtProc('close')
D handle 10I 0 value
D O_RDONLY C 1
D O_WRONLY C 2
D O_CREAT C 8
D O_TRUNC C 64
D msg S 80A
D x S 10I 0
C* close them if they're open
c for x = 0 to 2
c callp close(x)
c endfor
c eval Msg = *blanks
* open up 0, 1, 2 as files.
c if open('/dev/qsh-stdin-null':O_RDONLY)<>0
c eval Msg = 'unable to open a fake STDIN'
c endif
c if open('/tmp/stdout-'+dsJobNo:
c O_WRONLY+O_CREAT+O_TRUNC: 511)<>1
c eval Msg = 'unable to open a fake STDOUT'
c endif
c if open('/tmp/stderr-'+dsJobNo:
c O_WRONLY+O_CREAT+O_TRUNC: 511)<>2
c eval Msg = 'unable to open a fake STDERR'
c endif
C* Ack! Something foiled my plans!
c if Msg <> *blanks
c for x = 0 to 2
c callp close(x)
c endfor
c endif
c return Msg
P E
*===============================================================
* File descriptors 0, 1 & 2 are used by unix-environments for
* stdin, stdout & stderr.
*
* Here we just direct those 3 descriptors to stream files
*===============================================================
P CloseIO B
D CloseIO PI
D close PR 10I 0 ExtProc('close')
D handle 10I 0 value
D unlink PR 10I 0 ExtProc('unlink')
D path * Value options(*string)
D x S 10I 0
c for x = 0 to 2
c callp close(x)
c endfor
c callp unlink('/tmp/stdout-'+dsJobNo)
c callp unlink('/tmp/stderr-'+dsJobNo)
P E
*---------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.