Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
SteveEly Absent Member.
Absent Member.
1568 views

Getting a response from a command line program

Jump to solution

I am trying to find the best way to call a command line .exe and get a response back. I tried C$SYSTEM but all I can get back is the called program's exit status. Any ideas?

Thanks, Steve

0 Likes
1 Solution

Accepted Solutions
Chuck Edgin Absent Member.
Absent Member.

RE: Getting a response from a command line program

Jump to solution

You can access a process using COBOL file I/O verbs, by defining it as a file using -P in the ASSIGN clause of the SELECT. Then you can read the output of the command using OPEN INPUT and READ verbs.

       select my-command assign to "-P ls -l /path/to/somedir"
           organization is line sequential
           file status is my-command-stat.

       FD my-command.
       01 output-line pic x(80).

       01 my-command-stat   pic x(02).
           88 my-command-eof value "10".

       ...
           open input my-command
           perform until my-command-eof
               read my-command next record
               ...etc...
       ...

You can also write to an external command, using OPEN OUTPUT and WRITE. You cannot use OPEN EXTEND or OPEN I-O.

This example assumes a Unix or Linux environment, but you can do this on Windows as well - but with some additional handling. Read the docs for detail: ACUCOBOL-GT User's Guide, Section 2.9.1

View solution in original post

0 Likes
3 Replies
JimRead Absent Member.
Absent Member.

RE: Getting a response from a command line program

Jump to solution

That depends on what kind of information you're trying to get out.  If you just want a status check of some sort, a named semaphore is quick and easy.  If you're trying to get data between the processes, then C$SOCKET might be your friend.

0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: Getting a response from a command line program

Jump to solution

You can access a process using COBOL file I/O verbs, by defining it as a file using -P in the ASSIGN clause of the SELECT. Then you can read the output of the command using OPEN INPUT and READ verbs.

       select my-command assign to "-P ls -l /path/to/somedir"
           organization is line sequential
           file status is my-command-stat.

       FD my-command.
       01 output-line pic x(80).

       01 my-command-stat   pic x(02).
           88 my-command-eof value "10".

       ...
           open input my-command
           perform until my-command-eof
               read my-command next record
               ...etc...
       ...

You can also write to an external command, using OPEN OUTPUT and WRITE. You cannot use OPEN EXTEND or OPEN I-O.

This example assumes a Unix or Linux environment, but you can do this on Windows as well - but with some additional handling. Read the docs for detail: ACUCOBOL-GT User's Guide, Section 2.9.1

View solution in original post

0 Likes
SteveEly Absent Member.
Absent Member.

RE: Getting a response from a command line program

Jump to solution

I am working with Windows but I will look at the User's Guide. That looks like it should do the trick. Thanks!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.