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

**URL:** <https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, ApplinX, Natural-on-Linux\
**Created:** [May 22, 2023, 12:53pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867 "2023-05-22T12:53:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonard.solomyak](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/leonard.solomyak/32/18779_2.png) [@leonard.solomyak](https://techcommunity.softwareag.com/u/leonard.solomyak)\
**Post date:** [May 22, 2023, 12:53pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/1 "2023-05-22T12:53:08Z")

</div>

#### _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

---

<div class="post-metadata">

**Author:** ![Luciano\_Pimenta](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/luciano_pimenta/32/7857_2.png) [@Luciano\_Pimenta](https://techcommunity.softwareag.com/u/Luciano_Pimenta)\
**Post date:** [May 22, 2023, 1:21pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/2 "2023-05-22T13:21:42Z")

</div>

Did you tested the same script invocation using USR1052N?

---

<div class="post-metadata">

**Author:** ![leonard.solomyak](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/leonard.solomyak/32/18779_2.png) [@leonard.solomyak](https://techcommunity.softwareag.com/u/leonard.solomyak)\
**Post date:** [May 22, 2023, 3:56pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/3 "2023-05-22T15:56:04Z")

</div>

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  
> …

.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [May 22, 2023, 10:13pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/4 "2023-05-22T22:13:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![leonard.solomyak](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/leonard.solomyak/32/18779_2.png) [@leonard.solomyak](https://techcommunity.softwareag.com/u/leonard.solomyak)\
**Post date:** [May 22, 2023, 10:37pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/5 "2023-05-22T22:37:52Z")

</div>

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

 ![image](https://global.discourse-cdn.com/techcommunity/original/3X/6/2/62785af6106862f182b72f333b1709340c10d927.png)

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

![image](https://global.discourse-cdn.com/techcommunity/original/3X/f/e/fe2df16e70f751b36d1d56f26c2bfb2be0cbbcd1.png)

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

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [May 22, 2023, 11:07pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/6 "2023-05-22T23:07:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [May 23, 2023, 8:15am UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/7 "2023-05-23T08:15:20Z")

</div>

Adding to what Ralph said earlier

> [@Ralph\_Zbrog](#):
>
> There is little difference between using CALL “SHCMD” or CALLNAT ‘USR1052N’.

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.

---

<div class="post-metadata">

**Author:** ![leonard.solomyak](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/leonard.solomyak/32/18779_2.png) [@leonard.solomyak](https://techcommunity.softwareag.com/u/leonard.solomyak)\
**Post date:** [May 23, 2023, 9:49pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/9 "2023-05-23T21:49:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [May 23, 2023, 11:34pm UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/10 "2023-05-23T23:34:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![leonard.solomyak](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/leonard.solomyak/32/18779_2.png) [@leonard.solomyak](https://techcommunity.softwareag.com/u/leonard.solomyak)\
**Post date:** [May 24, 2023, 12:06am UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/11 "2023-05-24T00:06:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [November 20, 2023, 12:06am UTC](https://techcommunity.softwareag.com/t/linux-script-called-by-natural-via-shcmd-loops-indefinitely-ignoring-pause-or-read/278867/12 "2023-11-20T00:06:38Z")

</div>

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