Linux script called by Natural via SHCMD loops indefinitely ignoring pause or read

Product/components used and version/fix level are you on:

Natural (Linux)
Bash script (Linux)

Detailed explanation of the problem:

The issue is encountered with a Linux script that is being invoked by a Natural program via SHCMD. The script includes a menu and secondary level scripts, operates as expected when run directly in the Linux shell. However, it goes into infinite loop when called from the Natural program.

The Natural program calls this script via SHCMD and directs the output to a file, which is then read and displayed on the screen.

This works perfectly with scripts that are self-terminating. However, we’re encountering a problem with scripts that contain ‘read’ or ‘pause’ commands, which are typically found within loops.

It seems that the Natural process that calls the script is inadvertently issuing an ‘Enter’ signal causing the script to enter into an infinite loop, rather than pausing or waiting for input as expected. We need to find a way to prevent this from happening and ensure that the ‘read’ or ‘pause’ commands function as intended when the script is called from the Natural program.

Error messages / full error message screenshot / log fileL

The Natural program stalls as the called script is looping infinitely

Is your question related to the free trial, or to a production (customer) instance?

Natural product is licensed

Have you installed all the latest fixes for the products and systems you are using?

The Natural version is 9,.1.4, Build 344

Did you tested the same script invocation using USR1052N?

When using USR1052N, the Natural program still hangs, however, this time, a group of three processes is created for the script, while only a single record appears in the script output.

Termination of this hanging Natural session triggers the processes to build up the output as they did previously.
Otherwise, termination of these processes first causes Natural session to regain control and revert with an error message: 6390, indicating an

invalid work file name

Script snippet
VIEW=“”
while ! [ “$VIEW” = “q” ]
do
echo this is my test
pause
done

Natural code


1 usr1052L
2 os-command (a253)
2 response (i4)

move #cmd to os-command
reset response
callnat ‘USR1052N’ usr1052L

define work file 1 #workfile
read work 1 #content
write #content

.

There is little difference between using CALL “SHCMD” or CALLNAT ‘USR1052N’. In both cases a shell is spawned, the shell executes while Natural waits for its completion, then Natural resumes execution. Any stdin the shell needs must be passed within your #cmd variable. Can you show us the contents of #cmd?

sure, please #cmd is displayed in the Natural session before being executed

Copying this displayed line into Linux prompt allows to execute this command as expected

image

As it was said before this works fine when the script is not expecting input

Natural cannot press ENTER, so the script will hang.

Have the user supply the input data to the Natural program which writes it to a WORK file, which then is redirected to stdin within the #cmd.

Adding to what Ralph said earlier

Please note that this may be true today, but it may no longer be true tomorrow, and there is no guarantee SHCMD will be there forever, USR1052N is the one and ONLY supported & documented method for this.

Could you kindly confirm whether the intermediate file is the sole method for displaying the output of the script within the Natural session that initiates this script?

From USR1052T

Interface USR1052N supports the internal option STDOUT.
If STDOUT is set in the optional parameter CMD-OPTIONS, the command
output is returned in the optional parameter CMD-OUTPUT.
For reading the command output work file 10 is used.

I would like to express my sincere gratitude for everyone’ insightful feedback. Your contributions have been extremely helpful and are greatly appreciated. Thank you for your time and effort.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.