Product/components used and version/fix level are you on:
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
while ! [ “$VIEW” = “q” ]
echo this is my test
2 os-command (a253)
2 response (i4)
move #cmd to os-command
callnat ‘USR1052N’ usr1052L
define work file 1 #workfile
read work 1 #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
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?
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.