SSIS Expression builder for MULTI line file ( Exec Process Task) - sql-server

My global task to create config file for WinSCP process, and it should be multi lines (no options). I try to use Expression builder for CMD/Echo to do this. And still file, tried all option with and without /C flag which is critical for SSIS cmd task. I have option to have task for each line and it's by back plan, but trying to see if I can come up and learn how to do this in single box. I example below I can create multi line Expression using + " " combo where second quotes on new line. But it's still not good for whole task, Looks like CMD /C need single line ??
All info displayed in pic below:
This is arguments I'm using now with WinSCP executable in System task.
open ud12345d264d7b8#magdaflyn.sharefileftp.com
option transfer binary
put c:\SFTP\Magda_Members_20190901.csv "/Business Intelligence Share/Zbignev/"
close
exit

Creating multi-line expression
In order to add new lines in SSIS expression you must use the carriage return and line feed characters \r\n:
"/C Echo line11 \r\n /C Echo " + #[User::Var3] + "Line222 \r\n /C Echo Line3 > Config.dat"
Executing multiple commands
If adding new lines didn't work, you can use && operator to run multiple command using CMD:
SSIS: Execute Multiple Commands with 1 line in Execute Process Task (Arguments)
Workaround
If all what I mentioned above didn't work, then try saving the whole command into a batch file, and execute this batch file from the Execute Process Task.

You can write two lines using this syntax:
/c "echo line1 && echo line2" > config.dat
Though, you do not need to create a config file for WinSCP. All WinSCP options can be configured on its command-line. So this may be XY problem.
And while it's not clear, you may actually be creating a script file, not a config file. You can instead specify all WinSCP commands on WinSCP command-line using /command switch:
winscp.com /command "open ud12345d264d7b8#magdaflyn.sharefileftp.com" "option transfer binary" "put c:\SFTP\Magda_Members_20190901.csv ""/Business Intelligence Share/Zbignev/""" "close" "exit"
WinSCP GUI can generate a command-line sample for you.
See also WinSCP article SFTP Task for SSIS/SSDT.
Though you actually better use WinSCP .NET assembly instead of scripting in SSIS. See Using WinSCP .NET Assembly from SQL Server Integration Services (SSIS).

Related

.Bat file to execute macro from attachmate EXTRA application

How to execute macro file (.ebm) using batch script ?
Attachmate extra application has macro recording option after recording it saves .ebm file (macro) in local system. I have written a batch file to execute this macro. But its not working.
Thanks in advance!!
How I do it manually - I goes to the application in the folder and double click opens the attachmate application, when click on "Tools" option it displays list of recorded macros from that list I click on a macro to execute it. How can I automate this using batch script. please suggest
Solution found, Updated the script below.
start "" - After start command, you can give title or empty string (Thanks to compo for help)
extra.exe - This will open your aplication
/h <hostname> - Find your hostname/ip address in Options>Settings>Connection
/m macro path - Which macro you need to execute
Updated Batch script
#echo off
start "" extra.exe /h "tplxsuper.xyz.com" /m "C:\Users\Public\Documents\Attachmate\EXTRA!\macros\HELLO.EBM"
exit
This is how I have done it. Take your macro and change the file extension from .ebm to .elf your macro will be executable from a BAT or VBS file.

SSIS Execute process task to copy 2 files into new file

Hi i wanted to copy the records of two csv files into a new file.
Task : Copy A + B into C
OR Copy A to B ( this is what i am doing but i don't know how via SSIS)
I used SSIS to do so using Execute Process Task . In order to verify i tried it in command prompt.
When i tried via SSIS package it fails i am not sure why here are the inputs for the executable and the arguement.
Thank you very much in advance
Recommendations:
Don't use \ when assigning a value (only in expressions)
You have to use /C before passing parameters to cmd.exe
Because you didn't specify the Working directory you should provide the full path for each file, if not Out.csv will be created in the package runtime folder.
The command must be like the following:
/C copy /b C:\Temp\Source.csv + C:\Temp\Destination.csv C:\Temp\Out.csv
Reference
Executing Command Prompt commands in SSIS

Start a batch file and close Cmd once it is finished

I have my application spread over multiple directories, each containing a part (e.g. web frontend, mobile application, administration, middleware, backend, ...).
In each of the directories I have one part, and a file compile.cmd which compiles that part and looks roughly like this:
#ECHO OFF
compiler prepare thisPart
compiler compile thisPart
copy resultingFile1 ../bundleDirectory
...
copy resultingFileN ../bundleDirectory
pause
The "pause" is so I can check the compiler output, whether compile failed and which error messages occurred, and then close the window with a single keystroke (mostly, space key).
I now want to have a batch file that calls all these batch files for different application parts in parallel, so I guess I have to open a new shell window for each.
So I wrote CompileAllParts.cmd like this:
cd part1
start "Compile part 1" compile.cmd
cd ../part2
start "Compile part 2" compile.cmd
cd ../part3
start "Compile part 3" compile.cmd
Positive is that I can influence the window title, but the drawback is that new Cmds are spawned which do not automatically close.
This is also part of the documentation of start:
If command is an internal cmd command or a batch file then the command processor is run with the /K switch to cmd.exe. This means that the window will remain after the command has been run.
Is there a hidden parameter to explicitly disable this behaviour?
combine start with cmd. First to set title and working folder, second to use /C and execute the command:
start "Compile part 1" /d "part1" cmd /c "d:\proper folder\compile.cmd"

Equivalent to cut command in batch scripts

Is there any utility in windows which carries out same operations done but cut command in unix.
I have input lets say A|B|C|D. Since "|" is the delimiter therefore I need to fetch all values separated by "|".
Kindly advise.
If you are trying to do this in a .cmd file you can probably find some examples by typing for /? into your command prompt. Otherwise if powershell is an option then it's as easy as using String.Split().

Force bat file to use non default cmd.exe

I'm writing a .bat file to handle some script generation automatically so I don't have to type in half a dozen command arguments each time I want to run it.
I have to run a vb script from the batch file
#call ..\Database\scripts\runscriptupdates.vbs
However the script will only run if using the the command prompt from
C:\Windows\SysWOW64\cmd.exe
By default the bat file uses the cmd.exe in system32
C:\Windows\System32\cmd.exe
Is there a way to force the batch file to use this cmd.exe to run the vbs file? I've been trawling the web for about an hour now and haven't found anything which helps (so far).
I've tried running the syswow64 with "start ..." however it doesn't seem to take the arguments after it.
Many thanks, Neil
You can try:
%windir%\SysWoW64\cmd.exe /c mybatch.bat
This will run the batch itself from a 32-bit command prompt. Thus, the call to your vbs will also be coming from a 32-bit command prompt.
I also had this problem, and I found the way to solve it.
You just need to change System Variables.
Go to Control Panel » System » Advanced System Settings » Environment Variables.
Find the variable ComSpec, then just click Edit... and change the path to "C:\Windows\SysWow64\cmd.exe"
Try typing this one line in your batch file.
%windir%\SysWoW64\cmd.exe /c ["]cscript [script name] [host options] [script arguments]["]
Where:
script name is the name of the script file, including the file name extension and any necessary path information.
host options are the command-line switches that enable or disable various Windows Script Host features. Host options are always preceded by two slashes (//).
script arguments are the command-line switches that are passed to the script. Script arguments are always preceded by one slash (/).
Example:
%windir%\SysWoW64\cmd.exe /c "cscript VoltageDrop.vbs /"Campbell.sin" "L08""
Note: In this line I do not pass any host options. This command will execute the string,
cscript VoltageDrop.vbs /"Campbell.sin" "L08"
as a command in the 32-bit command prompt.

Resources