Show/Hide Toolbars

Reporting Services CMD

Navigation: Quick Start

Batch files

Scroll Prev Top Next More

Calling batch files

 

1. Batch files can be called within SSRS CMD

 

 call <name of batch file to execute>

 

2. Added to the SSRS CMD command line.

 

 ssrscmd call <name of batch file>

 

 

3. Scheduling a batch file can be run from the inbuilt schedule with Microsoft Windows.

 

 

 

 

 

Batch files are useful to automate multiple commands in a single file. To run a batch file you need to use the command call

 

 

Passing variables into the batch file. Enter the values after the call command. example batch file.

 

 

 

In addition to the list of commands there are additional commands that will be useful. There is an example script showing these commands in action

 

 

Echo

@Echo

Rem

Goto

If exists

If not exists

Exit

 

 

there is an example to show the above commands working.

 

 

Echo

 

Exit batch file

 

 

Echo

 

Echo is used to output the item to the screen Echo [item]. If you want to output a new line to the screen use echo.  (no space between echo and .)

 

eg

 

 echo Hello world

 

 this will output Hello world to the screen

 

 

@echo

 

This is used to enable or disable output the command before the command resultant output is displayed.

 

eg.

 

@echo on

         this will display the command

 

@echo off

         this will not display the command

 

 

 

 

Rem

 

this is a comment used to comment the batch file. No output to the screen

 

 

Goto <label>

 

the goto command allows you to go to another part of the batch file. Here is a example.. The goto label is called addreport to identify where to go in the batch file the same label must be placed in the batch file with a colon before the label. If the label cannot be found the script will stop with an error message.

 

 

1        echo Adding a report

2        goto addreport

6        :ret

7        quit

 

3        :addreport

4        rem this is the start of the part of the batch file that adds reports

 

5        goto ret

 

 

 

In this example above the flow control is listed as numbers to the left of the commands.

 

 

If Exists

If exists <file/folder> command to run.

 

 This checks if an item (file/folder) exists, if it does the command to run is executed

 Note the <File/folder> must be enclosed in quotes

 example

 

         if exists "A Folder" echo the folder "A Folder" does not exist

 

If Not Exists

If not exists <file/folder>  Command to run

 

 This checks if an item (file/folder) does not exist, if it does not exist the command to run is executed

 Note the <File/folder> must be enclosed in quotes

 example

 

         if not exist "A Folder" echo the folder "A Folder" does not exist

 

 

 

Example Script

 

rem this is an example to show the above commands

echo Starting example

echo.

 

if not exists "AFolder" goto createFolder

rem this is the line that runs if the folder AFolder does exist.

:dirListRoot

 

rem this lists all items in the folder and sub folders from the root

cd \

dir /s

 

rem rather than quit here use goto exit at the end so there is no risk of any other command running

goto exit

 

:createFolder

md AFolder

echo AFolder Created

goto dirListRoot

 

 

:exit

rem quit script

quit