Skip to main content

Linux Command from Cobol Program

  • October 28, 2019
  • 2 replies
  • 0 views

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

 

2 replies

Stephen Gennard
Forum|alt.badge.img

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

 

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"'.

 


  • November 1, 2019

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

 

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