Highlighted
Trusted Contributor.
Trusted Contributor.
296 views

Linux Command from Cobol Program

Jump to solution

There is a post in the Cobol Forum regarding executing Unix commands from within a Cobol program using CALL "SYSTEM"..... When I try to do the same thing from a program running on a Linux-server the program ends with return code 512

77  ws-command pic x(40) value 'ls -l > lsout.txt'.

77 ws-rc-out    pic s9(9) comp.

call 'system' using ws-command returning ws-rc-out.

display 'RC=' ws-rc-out

The file lsout.txt is created but it is empty.

The return code is +000000512

I have tried executing windows-commands when I run program in eclipse and that works well.

Am I barking up the wrong tree or is this possible to achieve?

Regards

/Peter

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Trusted Contributor.
Trusted Contributor.
Sorry for late response. Ending the command with x'00' did the trick.
Works fine now.

View solution in original post

2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

First use "SYSTEM" rather than "system", as this will ensure it works with screen handling.

Next the API needs to be zero terminated... for example:
 77 ws-command pic x(40) value z"ls -l > lsout.txt".

I would also use:

 77 ws-command pic x(80) value z'/bin/bash -c "ls -l >lsout.txt"'.

 

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.
Sorry for late response. Ending the command with x'00' did the trick.
Works fine now.

View solution in original post

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.