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.
Highlighted
PeterI_vfb Trusted Contributor.
Trusted Contributor.
85 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
PeterI_vfb Trusted Contributor.
Trusted Contributor.

Re: Linux Command from Cobol Program

Jump to solution
Sorry for late response. Ending the command with x'00' did the trick.
Works fine now.

2 Replies
Micro Focus Expert
Micro Focus Expert

Re: Linux Command from Cobol Program

Jump to solution

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
PeterI_vfb Trusted Contributor.
Trusted Contributor.

Re: Linux Command from Cobol Program

Jump to solution
Sorry for late response. Ending the command with x'00' did the trick.
Works fine now.

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.