
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Getting a response from a command line program
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Getting a response from a command line program
I am working with Windows but I will look at the User's Guide. That looks like it should do the trick. Thanks!