# \[Automation\] External Batch File & Variables - Not working

**URL:** <https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546>\
**Category:** Toad Data Point & Toad Intelligence Central\
**Created:** [February 5, 2013, 8:27pm UTC](https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546 "2013-02-05T20:27:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![N.B](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@N.B](https://forums.toadworld.com/u/N.B)\
**Post date:** [February 5, 2013, 8:27pm UTC](https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546/1 "2013-02-05T20:27:48Z")

</div>

For some reason, I cannot seem to get an external batch file to “take” variables that I’m passing to it from the “Run Program” automation activity.

Here’s the setup:

Program: …\BSR\BSRXH\West\_SP\_Copy.bat  
Arguments: #Yr# “#Mth#” #Date# #Date-15#

#Mth# is surrounded by quotes because it resolves to 02 FEB, and Windows doesn’t allow a space in the file name path that isn’t surrounded by quotes.

And here’s the batch file:

XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\05 D PND NO XFER “%3”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\05 D PND XFER “%3”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\05 D CMP “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y

XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\32 D PND NO XFER “%3”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\32 D PND XFER “%3”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\32 D CMP “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y

XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\09 D PND NO XFER “%3”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\09 D PND XFER “%3”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2"\09 D CMP “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2"" /I /Y

%1 is mapped to #Yr#  
%2 is mapped to #Mth#  
%3 is mapped to #Date#  
%4 is mapped to #Date-15#

When I run this manually from the command line, passing the real values to the batch file, it works perfectly. But when run from the “Run Program” activity - nothing happens. TDA reports that the program exited successfully, but no files are actually copied to the remote directory.

Is there something I’m just missing?

---

<div class="post-metadata">

**Author:** ![N.B](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@N.B](https://forums.toadworld.com/u/N.B)\
**Post date:** [February 11, 2013, 6:13pm UTC](https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546/2 "2013-02-11T18:13:39Z")

</div>

I’ve both simplified this a bit and made it slightly more complicated - again, it runs just fine when calling from the command line and passing the data that would be in the variables:

Program: C:\Automation\West\_SP\_Copy.bat  
Arguments: #Yr# #b\_mm# #b\_mon# #Date# #Date-15#

And here’s the batch file:

XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\05 D PND NO XFER “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\05 D PND XFER “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\05 D CMP “%5”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y

XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\32 D PND NO XFER “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\32 D PND XFER “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\32 D CMP “%5”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y

XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\09 D PND NO XFER “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\09 D PND XFER “%4”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y  
XCOPY “\FILESERVER\IS\REPORTS”%1"\XH"%2" “%3”\09 D CMP “%5”.xlsx" “\SHAREPOINT\REGION\IS\DSR\XH\West”%1""%2" “%3"” /I /Y

%1 is mapped to #Yr#  
%2 is mapped to #b\_mm#  
%3 is mapped to #b\_mon#  
%4 is mapped to #Date#  
%5 is mapped to #Date-15%

This is getting quite frustrating - I don’t get any error messages from Toad, but yet this will not work in the “Run Program” activity.

---

<div class="post-metadata">

**Author:** ![N.B](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@N.B](https://forums.toadworld.com/u/N.B)\
**Post date:** [February 14, 2013, 2:28pm UTC](https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546/3 "2013-02-14T14:28:14Z")

</div>

Further testing yielded a log file that shows that the XCOPY command is being issued from the batch file - however, it appears as though it’s not actually being run - I’m not sure if this is because of how TDA executes the batch file or what.

I know that the batch file is good, because if I run it by hand and pass the parameters along, it works perfectly.

What am I missing?

---

<div class="post-metadata">

**Author:** ![mercier104\_000](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mercier104\_000](https://forums.toadworld.com/u/mercier104_000)\
**Post date:** [February 18, 2013, 8:19am UTC](https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546/4 "2013-02-18T08:19:03Z")

</div>

hi,

You should try to use “find and replace” automation module to write variables directly in the batch file before running it…

Regards.

---

<div class="post-metadata">

**Author:** ![IgorM](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/igorm/32/116_2.png) [@IgorM](https://forums.toadworld.com/u/IgorM)\
**Post date:** [February 18, 2013, 1:22pm UTC](https://forums.toadworld.com/t/automation-external-batch-file-variables-not-working/7546/5 "2013-02-18T13:22:02Z")

</div>

For some reason variables in a Run activity are working fine in development build but are not in release/beta build. We’re investigating it. Suggested using of Find&Replace activity to substitute values in batch file might be a possible workaround.

Igor.
