Passing Variable values into .bat file using Execute Process Task - sql

I have a ssis package that has a foreach loop container. I am trying to use .bat file within the foreach loop container using execute Process task. How do I configure my Execute Process task to pass the value into my .bat file?
Here is my sequence:
Execute sql task (passing my variable into the foreach)--> Foreach loop container----> Execute Process Task (I need help with executables, arguments....)

Create 2 variables in your SSIS package.
The first one would have the FileName along with the entire path.
The other variable will have its property 'Evaluate As Expression' set to TRUE and set its Expression to the following -
"local:" + #[System::FilePathVariable] + " -d HDMS:/To_HDMS/"
As soon as the second variable is referenced in your SSIS package, its expression (the one written above) would execute.
Say the FilePathVariable had the value "D:\Folder1\Folder2\FileName"; so, the value of the second variable after its expression is evaluated would be "local:D:\Folder1\Folder2\FileName -d HDMS:/To_HDMS/"
You need to pass this as an argument to your batch file. This would be done as explained in my previous post above.
In your batch file, have the command as -
C:
cd \Program Files\WS_FTP Pro\
wsftppro -s %1
Please try and let us know in case it doesn't work for you.

Related

SSIS is doubling up backslashes

I am loading some file names and locations as variables into SSIS, then tried using foreach loop to execute a process task.
after a few unsuccessful attempts I realized SSIS is doubling up all the Backslashes in the fields I am loading into my variables. hence the network addresses not working.
can we stop this behavior?
What I load:
"\\BBBB001\shared\GGGG\PiMSSSRSReportsPath\THM022\HHHH-NextWorkingDay-at1530.pdf"
What I get:
"\\\\BBBB001\\shared\\GGGG\\PiMSSSRSReportsPath\\THM022\\HHHH-NextWorkingDay-at1530.pdf"
SSIS Execute Process task:
as you can see foxit reader doesn't recognize the later filename with double backslashes. if I manually inter the first value it will work.
For future reference, I found a workaround:
Instead of adding variables in Arguments section, I created a single variable including all the parameters for the file to be printed. something like this:
/t "FileLocation\FileName.pdf" PrinterName
And then put this variable in the expression section of the Execute process task, add argument and put that final variable in front it. like this:

Powershell: Specify file path as variable

I am running the following SQL query through a powershell script and need to run the script multiple times against different files. So what I am trying to figure out is how to specify a file path as a variable when I run the script?
update [$Db_name].[dbo].[$BatchTable]
set [$Db_name].[dbo].[$BatchTable].Wave = 'Wave1.1'
from [$Db_name].[dbo].[$BatchTable]
inner join OPENROWSET(BULK 'FilePath\file.csv',
FORMATFILE= 'E:\import.xml') AS a
on ([$Db_name].[dbo].[$BatchTable].Name= a.Name) and
([$Db_name].[dbo].[$BatchTable].Domain = a.Domain)
The 'FilePath\file.csv' is the file path I need to define as a variable so that my code would instead look like this:
inner join OPENROWSET(BULK '$INPUTFILEPATH',
FORMATFILE= 'E:\import.xml') AS a
Any help or potentially better methods to accomplish this would help very much.
From the command like I want to be able to run the script like this:
CMD: updatescript.ps1 $INPUTFILEPATH = C:\Documents\myfile.csv
Again, I'm not sure this is the best way to go about this?
You're nearly there.
You will need to add a parameter block at the very start of your script e.g.
Param(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_ -PathType 'leaf'})]
[string] $InputFilePath
)
This creates a mandatory (not optional) string parameter, called InputFilePath, and the ValidateScript is code used to validate the parameter, in this case checking the file exists using the Test-Path cmdlet and pathtype of leaf (if checking existence of a directory use 'container').
When running your script use the syntax below:
updatescript.ps1 -INPUTFILEPATH "C:\Documents\myfile.csv"
and in the script use the variable as the path exactly as in your question:
inner join OPENROWSET(BULK '$INPUTFILEPATH',
FORMATFILE= 'E:\import.xml') AS a
NOTE: in powershell when using parameters when running a script you only need to use the least amount of characters that uniquely identify that parameter from all the others in your param block - in this case -I works just as well as -InputFilePath.
You can pass command line parameters to the powershell script using param.
Example:
param(
[string]$INPUTFILEPATH
)
And then call the script as follows:
updatescript.ps1 -INPUTFILEPATH C:\Documents\myfile.csv
More details about cmd line parameters can be found here

TCL: how to execute program using enviorment PATH variable

I've got following line in my script
exec $::env(PATH)/program.exe
In my env PATH variable I've got a directory where I've got this executable file. For example:
PATH env variable got among other this - D:\my_program\bin
I've got error:
Error:
couldn't execute C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;D:\my_program\bin;\program": no such file or directory
Any suggest how to execute .exe file using system variable like PATH in tcl?
Thanks
PS
OK, when I've create a new env variable (PATH1 - without any other paths, just one) and set .exe file path to it, it seems to work. Any solution to do with PATH (with multiple paths) excluding set D:\my_program\bin in first place?
You should simply use the Tcl library function made for this auto_execok.
Try this:
exec {*}[auto_execok program.exe]
It automatically searches the PATH and constructs the right path for using with exec.
For example, to start notepad.exe:
% auto_execok notepad.exe
C:/windows/system32/notepad.exe
% exec {*}[auto_execok notepad.exe]
To see why the {*} is needed, have a look at http://wiki.tcl.tk/765. Basically auto_execok is pretty smart and can return a list, if needed, e.g. for running start on windows, which needs the expansion to work properly with exec.

Pass SSIS variable to Process task

How to pass variables defined in SSIS as parameters to SSIS Process task that runs a bat file.
In the bat file the user name and password would be replaced with %1 argument and input will be passed from the script task that will receive input from a .NET front-end.
Please do help with screenshots if possible
Thanks
In the script task, write the value to a SSIS variable.
In the Exec Process task, modify the Arguments expression, to pass the variable into the task
There is a screenshot on this thread How to execute a Process Task where the Executable path comes from a user Variable

batch scripting: how to get parent dir name without full path?

I'm working on a script that processes a folder and there is always one file in it I need to rename. The new name should be the parent directory name. How do I get this in a batch file? The full path to the dir is known.
It is not very clear how the script is supposed to become acquainted with the path in question, but the following example should at least give you an idea of how to proceed:
FOR %%D IN ("%CD%") DO SET "DirName=%%~nxD"
ECHO %DirName%
This script gets the path from the CD variable and extracts the name only from it to DirName.
You can use basename command:
FULLPATH=/the/full/path/is/known
JUSTTHENAME=$(basename "$FULLPATH")
You can use built-in bash tricks:
FULLPATH=/the/full/path/is/known
JUSTTHENAME=${FULLPATH##*/}
Explanations:
first # means 'remove the pattern from the begining'
second # means 'remove the longer possible pattern'
*/ is the pattern
Using built-in bash avoid to call an external command (i.e. basename) therefore this optimises you script. However the script is less portable.