# Gwcmd causes batch file to exit after restoring gateway backup

**URL:** <https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518>\
**Category:** Ignition\
**Created:** [November 11, 2020, 4:48am UTC](https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518 "2020-11-11T04:48:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [November 11, 2020, 4:48am UTC](https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518/1 "2020-11-11T04:48:32Z")

</div>

I am writing a batch file to set up a few things on a new Ignition Gateway PC. The first thing it does is to restore a gateway backup. Following that, I want it to do things like open ports in the firewall and so on.

However, as soon as the gwcmd command executes (successfully), the batch file exits.

Relevant code:

```auto
@echo off
set dirpath=%~dp0
cd "C:/Program Files/Inductive Automation/Ignition"
echo Restoring gateway backup...
set /p gwname="Please enter a name for the Gateway: "
gwcmd --restore "%dirpath%\IgnitionGateway.gwbk" --name %gwname% --promptyes
pause
echo do other things...

```

The gwcmd command is successful - the gateway backup is restored with the specified name, and it restarts and is otherwise functional. However, as soon as the restore is complete, it very briefly flashes a message about being successful and closes the batch file. With the next line of the batch file being `pause`, I’m confident that it’s not code further down causing the issue.

Is this normal behaviour? Is there any way to fix it?

Edit: The batch file is being run as an administrator.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2020, 1:32pm UTC](https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518/2 "2020-11-11T13:32:26Z")

</div>

> [@ASF](#):
>
> Is this normal behaviour?

Yes, due to the way gwcmd is called.

> [@ASF](#):
>
> Is there any way to fix it?

Also yes. 🙂 Use a call function.  
[https://www.robvanderwoude.com/call.php](https://www.robvanderwoude.com/call.php)

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [November 11, 2020, 11:12pm UTC](https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518/3 "2020-11-11T23:12:19Z")

</div>

Thanks Jordan. So the best approach is to put my gwcmd snippets in their own batch file and call them from my master setup batch file. That I can do.

Is there any way to have the gwcmd batch file return a result to the master setup batch file, so that I know whether or not it succeeded?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 12, 2020, 12:24am UTC](https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518/4 "2020-11-12T00:24:11Z")

</div>

You should be able to look at the ERRORLEVEL

ss64 is probably where I should have sent you the first time. 😉

[https://ss64.com/nt/errorlevel.html](https://ss64.com/nt/errorlevel.html)

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [November 16, 2020, 1:35am UTC](https://forum.inductiveautomation.com/t/gwcmd-causes-batch-file-to-exit-after-restoring-gateway-backup/40518/5 "2020-11-16T01:35:43Z")

</div>

Thanks. Assuming that as usual, error code 0 = success, anything else = problems?

One final question - is it possible to do an online license activation with the utility? I see that there’s an option for creating an offline activation file, but it doesn’t appear that there’s any other license-related commands.
