Discussion:
Unix-question
(too old to reply)
scott Ford
2017-08-29 16:36:34 UTC
Permalink
Guys/Gals:

I was reading through IBM Unix services manuals and have a pipe question..
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, i *think* the answer is "yes". If so in a Single Thread STC would
the STC wait for the response ?? or does it depend on your code..I am
dealing with LE Cobol and want to utilize the nice features of Unix which i
am somewhat familiar.

Regards,
--
*IDMWORKS *

Scott Ford

z/OS Dev.




“By elevating a friend or Collegue you elevate yourself, by demeaning a
friend or collegue you demean yourself”



www.idmworks.com

***@idmworks.com

Blog: www.idmworks.com/blog





*The information contained in this email message and any attachment may be
privileged, confidential, proprietary or otherwise protected from
disclosure. If the reader of this message is not the intended recipient,
you are hereby notified that any dissemination, distribution, copying or
use of this message and any attachment is strictly prohibited. If you have
received this message in error, please notify us immediately by replying to
the message and permanently delete it from your computer and destroy any
printout thereof.*

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Paul Gilmartin
2017-08-29 16:55:59 UTC
Permalink
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe question..
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, i *think* the answer is "yes". If so in a Single Thread STC would
the STC wait for the response ?? or does it depend on your code..I am
dealing with LE Cobol and want to utilize the nice features of Unix which i
am somewhat familiar.
Many questions:

How are you creating the pipe? Named or unnamed?

How are you issuing the UNIX command?

Is it a shell command?

Did you put it in background with the '&' operator?

Are you reading the output with a nonblocking read?

Are you depending on the system buffer (131kB, I believe)
to circumvent deadlock?

Are you using select() to be notified of available output?

Did you close the input end of the pipe in the parent process
space in order to be able to detect end of information?

Are you using waitpid() on the child?

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
scott Ford
2017-08-29 17:44:23 UTC
Permalink
Gil,
Can u talk off list ?

On Tue, Aug 29, 2017 at 12:57 PM Paul Gilmartin <
Post by scott Ford
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe
question..
Post by scott Ford
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, i *think* the answer is "yes". If so in a Single Thread STC
would
Post by scott Ford
the STC wait for the response ?? or does it depend on your code..I am
dealing with LE Cobol and want to utilize the nice features of Unix
which i
Post by scott Ford
am somewhat familiar.
How are you creating the pipe? Named or unnamed?
How are you issuing the UNIX command?
Is it a shell command?
Did you put it in background with the '&' operator?
Are you reading the output with a nonblocking read?
Are you depending on the system buffer (131kB, I believe)
to circumvent deadlock?
Are you using select() to be notified of available output?
Did you close the input end of the pipe in the parent process
space in order to be able to detect end of information?
Are you using waitpid() on the child?
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Scott Ford
IDMWORKS
z/OS Development

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
scott Ford
2017-08-29 17:50:51 UTC
Permalink
So my question is where do I find a example of a pipe call and retrieve
...this would help me
Post by scott Ford
Gil,
Can u talk off list ?
On Tue, Aug 29, 2017 at 12:57 PM Paul Gilmartin <
Post by scott Ford
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe
question..
Post by scott Ford
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, i *think* the answer is "yes". If so in a Single Thread STC
would
Post by scott Ford
the STC wait for the response ?? or does it depend on your code..I am
dealing with LE Cobol and want to utilize the nice features of Unix
which i
Post by scott Ford
am somewhat familiar.
How are you creating the pipe? Named or unnamed?
How are you issuing the UNIX command?
Is it a shell command?
Did you put it in background with the '&' operator?
Are you reading the output with a nonblocking read?
Are you depending on the system buffer (131kB, I believe)
to circumvent deadlock?
Are you using select() to be notified of available output?
Did you close the input end of the pipe in the parent process
space in order to be able to detect end of information?
Are you using waitpid() on the child?
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Scott Ford
IDMWORKS
z/OS Development
--
Scott Ford
IDMWORKS
z/OS Development

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Lou Losee
2017-08-29 18:26:06 UTC
Permalink
http://tldp.org/LDP/lpg/node11.html

examples using C

--
Artificial Intelligence is no match for Natural Stupidity
- Unknown
Post by scott Ford
So my question is where do I find a example of a pipe call and retrieve
...this would help me
Post by scott Ford
Gil,
Can u talk off list ?
On Tue, Aug 29, 2017 at 12:57 PM Paul Gilmartin <
Post by scott Ford
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe
question..
Post by scott Ford
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, i *think* the answer is "yes". If so in a Single Thread STC
would
Post by scott Ford
the STC wait for the response ?? or does it depend on your code..I am
dealing with LE Cobol and want to utilize the nice features of Unix
which i
Post by scott Ford
am somewhat familiar.
How are you creating the pipe? Named or unnamed?
How are you issuing the UNIX command?
Is it a shell command?
Did you put it in background with the '&' operator?
Are you reading the output with a nonblocking read?
Are you depending on the system buffer (131kB, I believe)
to circumvent deadlock?
Are you using select() to be notified of available output?
Did you close the input end of the pipe in the parent process
space in order to be able to detect end of information?
Are you using waitpid() on the child?
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Scott Ford
IDMWORKS
z/OS Development
--
Scott Ford
IDMWORKS
z/OS Development
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
John McKown
2017-08-29 17:13:17 UTC
Permalink
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe question..
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, i *think* the answer is "yes". If so in a Single Thread STC would
the STC wait for the response ?? or does it depend on your code..I am
dealing with LE Cobol and want to utilize the nice features of Unix which i
am somewhat familiar.
​You can set the descriptor to be non-blocking using the BPX1FCT call.
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxb100/fct.htm

When you use the F_SETL option to set the file attribute to include the
O_NONBLOCK. When you do a read, BPX1RED, on this file descriptor, you will
get an EAGAIN response instead of waiting. Or you could use BPX1POL to see
if data can be read from (or written to) the given file descriptor without
waiting.
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxb100/pol.htm

You could also use the BPX1SEL (select) call to see which FDs, if any, have
data available. If you are used to do BSAM READ statements where you can
WAIT on an ECB, the BPX1SEL can work in a similar manner.

I am not aware of any way to have a "exit routine" be scheduled as a
"signal" that data is available to be read, or written, without blocking.
IBM UNIX does not implement asynchronous I/O in UNIX.
Post by scott Ford
Regards,
--
*IDMWORKS *
Scott Ford
z/OS Dev.
--
Caution! The OP is an hyperpolysyllabicsesquipedalianist and this email may
cause stress to those with hippopotomonstrosesquipedaliophobia.

Maranatha! <><
John McKown

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Paul Gilmartin
2017-08-29 21:57:24 UTC
Permalink
Post by John McKown
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe question..
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, ...
​You can set the descriptor to be non-blocking using the BPX1FCT call.
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxb100/fct.htm
...
I wondered briefly, naively.whether popen() might be the simplest
approach to this problem. Then I came to my senses and remembered,
it's FILE * popen( ... ); and COBOL is probably not FILE*-savvy.
(Or is it?) It's a pity there isn't a more basic popen() returning a
descriptor rather than a FILE*.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
scott Ford
2017-09-02 21:23:36 UTC
Permalink
Gil,

Where I have questions are :

How can a LE enable application, using COBOL, C , etc. call UNIX services,
perform a function a UNIX function
And retrieving output back to COBOL..hence I would have to , have COBOL
call C issue 'popen' build pipe, send commands
Etc.., is this correct ?

Scott


On Tue, Aug 29, 2017 at 5:58 PM Paul Gilmartin <
Post by scott Ford
Post by John McKown
Post by scott Ford
I was reading through IBM Unix services manuals and have a pipe
question..
Post by John McKown
Post by scott Ford
If I as a STC ..issue a Unix command after a PIPE was established and
retrieve output of the
command, ...
​You can set the descriptor to be non-blocking using the BPX1FCT call.
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxb100/fct.htm
Post by John McKown
...
I wondered briefly, naively.whether popen() might be the simplest
approach to this problem. Then I came to my senses and remembered,
it's FILE * popen( ... ); and COBOL is probably not FILE*-savvy.
(Or is it?) It's a pity there isn't a more basic popen() returning a
descriptor rather than a FILE*.
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Scott Ford
IDMWORKS
z/OS Development

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Paul Gilmartin
2017-09-03 00:08:26 UTC
Permalink
Post by scott Ford
How can a LE enable application, using COBOL, C , etc. call UNIX services,
perform a function a UNIX function
And retrieving output back to COBOL..hence I would have to , have COBOL
call C issue 'popen' build pipe, send commands
Etc.., is this correct ?
First, I'm COBOL-ignorant,

I believe (I'm not doing a lot of research) popen() is not a system call but a CRTL function.
You'd probably need a C bridge.

popen() returns a stream pointer (FILE *), not likely to be useful in COBOL.

The command is an argument to popen() It may be a compound.

I might imagin in C:

int filedes[ 2 ]

pipe( filedes )
popen( "cmd1; cmd2; ...; } >filedes[ 1 ] 2>&1", "r" ); /* omitting needed sprintf(); */

(Would it be easier to use spawn() rather than popen()?)

In COBOL (or C):
call BPXWDYN( alloc dd(DDNAME) path( /dev/fd/filedes[ 0 ] ) filedata(TEXT) ... " )
(or however you do a DYNALLOC in COBOL.)

Then OPEN and READ command output from DDNAME.

I suspect John M. (or Charles M.) might know far more, if you choose to
impose on them.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-09-03 00:40:34 UTC
Permalink
Hopefully John M. because Charles M. is a little lost! I've never used popen().

If I had to add "UNIX services" to a COBOL program I think I would link (statically or dynamically) to a C program and do the UNIX stuff directly from there. But I have no idea if that would work well or what the gotcha's would be -- that would just be my first direction.

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Paul Gilmartin
Sent: Saturday, September 2, 2017 5:10 PM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: Unix-question
Post by scott Ford
How can a LE enable application, using COBOL, C , etc. call UNIX
services, perform a function a UNIX function And retrieving output back
to COBOL..hence I would have to , have COBOL call C issue 'popen' build
pipe, send commands Etc.., is this correct ?
First, I'm COBOL-ignorant,

I believe (I'm not doing a lot of research) popen() is not a system call but a CRTL function.
You'd probably need a C bridge.

popen() returns a stream pointer (FILE *), not likely to be useful in COBOL.

The command is an argument to popen() It may be a compound.

I might imagin in C:

int filedes[ 2 ]

pipe( filedes )
popen( "cmd1; cmd2; ...; } >filedes[ 1 ] 2>&1", "r" ); /* omitting needed sprintf(); */

(Would it be easier to use spawn() rather than popen()?)

In COBOL (or C):
call BPXWDYN( alloc dd(DDNAME) path( /dev/fd/filedes[ 0 ] ) filedata(TEXT) ... " ) (or however you do a DYNALLOC in COBOL.)

Then OPEN and READ command output from DDNAME.

I suspect John M. (or Charles M.) might know far more, if you choose to impose on them.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
scott Ford
2017-09-03 00:45:57 UTC
Permalink
Charles,


That was my thinking ..Gil unfortunately I am stuck with COBOL trying to
convince the powers-to-be to go to C++.
I have Threaded C pro types working for various functions we do.

One of things that I would like to do is call UNIX TSOCMD ..pass security
calls to it, still need more research ..

Scott
Post by Charles Mills
Hopefully John M. because Charles M. is a little lost! I've never used popen().
If I had to add "UNIX services" to a COBOL program I think I would link
(statically or dynamically) to a C program and do the UNIX stuff directly
from there. But I have no idea if that would work well or what the gotcha's
would be -- that would just be my first direction.
Charles
-----Original Message-----
Behalf Of Paul Gilmartin
Sent: Saturday, September 2, 2017 5:10 PM
Subject: Re: Unix-question
Post by scott Ford
How can a LE enable application, using COBOL, C , etc. call UNIX
services, perform a function a UNIX function And retrieving output back
to COBOL..hence I would have to , have COBOL call C issue 'popen' build
pipe, send commands Etc.., is this correct ?
First, I'm COBOL-ignorant,
I believe (I'm not doing a lot of research) popen() is not a system call
but a CRTL function.
You'd probably need a C bridge.
popen() returns a stream pointer (FILE *), not likely to be useful in COBOL.
The command is an argument to popen() It may be a compound.
int filedes[ 2 ]
pipe( filedes )
popen( "cmd1; cmd2; ...; } >filedes[ 1 ] 2>&1", "r" ); /* omitting
needed sprintf(); */
(Would it be easier to use spawn() rather than popen()?)
call BPXWDYN( alloc dd(DDNAME) path( /dev/fd/filedes[ 0 ] )
filedata(TEXT) ... " ) (or however you do a DYNALLOC in COBOL.)
Then OPEN and READ command output from DDNAME.
I suspect John M. (or Charles M.) might know far more, if you choose to impose on them.
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Scott Ford
IDMWORKS
z/OS Development

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-09-03 01:12:28 UTC
Permalink
Elaborating a little bit, it seems like a very promising approach:

- COBOL calling C seems to be fully supported (no personal experience)
- C invoking UNIX services is about as basic as it gets
- And C has the power to bridge readily any "incompatibilities" (e.g., "the COBOL programmer wants to pass this value in upper case but it needs to be in lower case for the called UNIX service"; or "this value will be passed fixed length; it needs to have the blanks stripped and be null-terminated").

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Charles Mills
Sent: Saturday, September 2, 2017 5:42 PM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: Unix-question

Hopefully John M. because Charles M. is a little lost! I've never used popen().

If I had to add "UNIX services" to a COBOL program I think I would link (statically or dynamically) to a C program and do the UNIX stuff directly from there. But I have no idea if that would work well or what the gotcha's would be -- that would just be my first direction.

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Paul Gilmartin
Sent: Saturday, September 2, 2017 5:10 PM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: Unix-question
Post by scott Ford
How can a LE enable application, using COBOL, C , etc. call UNIX
services, perform a function a UNIX function And retrieving output back
to COBOL..hence I would have to , have COBOL call C issue 'popen' build
pipe, send commands Etc.., is this correct ?
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Paul Gilmartin
2017-09-03 01:56:26 UTC
Permalink
Post by Charles Mills
- COBOL calling C seems to be fully supported (no personal experience)
- C invoking UNIX services is about as basic as it gets
- And C has the power to bridge readily any "incompatibilities" (e.g., "the COBOL programmer wants to pass this value in upper case but it needs to be in lower case for the called UNIX service"; or "this value will be passed fixed length; it needs to have the blanks stripped and be null-terminated").
Are all the BPX1* callable services available directly in COBOL?

And BPXBATCH PARM='SH { cmd1; cmd2; ... ; } &'? (I've never mastered the intricacies
of its "local spawn" variant.)

So: BPX1PIP to create a pipe. (Be sure the descriptors are >2.)
BPXWDYN to allocate dd(STDOUT) to the *input* (yes) end of the pipe.
BPXWDYN to allocate dd(COBOLDD) to the output end of the pipe
BPXBATCH PARM='SH { cmd1; cmd2; ... ; } 2>&1 &' to run the commands in background.
(Does COBOL ignore the archaic 100-character limit?)
Read the command output from COBOLDD

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
scott Ford
2017-09-03 03:13:18 UTC
Permalink
I gave to look, in Assembler sure ..


On Sat, Sep 2, 2017 at 9:58 PM Paul Gilmartin <
Post by Charles Mills
Post by Charles Mills
- COBOL calling C seems to be fully supported (no personal experience)
- C invoking UNIX services is about as basic as it gets
- And C has the power to bridge readily any "incompatibilities" (e.g.,
"the COBOL programmer wants to pass this value in upper case but it needs
to be in lower case for the called UNIX service"; or "this value will be
passed fixed length; it needs to have the blanks stripped and be
null-terminated").
Are all the BPX1* callable services available directly in COBOL?
And BPXBATCH PARM='SH { cmd1; cmd2; ... ; } &'? (I've never mastered the intricacies
of its "local spawn" variant.)
So: BPX1PIP to create a pipe. (Be sure the descriptors are >2.)
BPXWDYN to allocate dd(STDOUT) to the *input* (yes) end of the pipe.
BPXWDYN to allocate dd(COBOLDD) to the output end of the pipe
BPXBATCH PARM='SH { cmd1; cmd2; ... ; } 2>&1 &' to run the commands in background.
(Does COBOL ignore the archaic 100-character limit?)
Read the command output from COBOLDD
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Scott Ford
IDMWORKS
z/OS Development

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Loading...