SSIS Creating a multiline DOS file - batch-file

I have to create a multiline DOS batch file in SSIS that looks like this:
cd e:\client\data
copy generic_output.txt clientname.yyyymmdd
where yyyymmdd is today's date
I have created quite a few single line DOS copy statements which do the copy (using a Derived column in the Data Flow) but can't come up with an approach that will allow me to create a template file that contains the (hardcoded) first line and then have a Data Flow task which writes out the first line and then have the Derived column be the second line.
Can I write out both commands in the Derived Column and put in a CR-LF in between the cd command and the copy command? Or is there a better approach?

I figured out a way that works. The cd command is fixed so I put that into a file. Then I used a Data Flow to build the COPY command in another file. Then I set up a copy.bat file to copy the 2 files, and then finally an Execute Process task to execute the final batch file. It works.
Thanks,
Dick

Related

CMD how to write merged text file name on first line

I have created cmd batch file to run several R script and each script have their own log files in same folder like below :
coc_prod_xgb.log
ds_prod_xgb.log
ccpa_prod_xgb.log
pletb_prod_xgb.log
and many more
Then I merge all text files into 1 log file
copy *.log all_log.log
The problem is sometimes there are errors on different jobs, so I need to know on which log this error occurs. Currently I have to open each log file one by one, because in the merged log file, I can't identify which log file that has this error.
How to modify above copy code so it will write file names on the 1st row then the next row will be log information and append the same process to next file
I can't find any option for cmd copy code to write file name, so i find another solution from this question.
Easiest way to add a text to the beginning of another text file in Command Line (Windows)
so it serve my needs, eventhough i have to write each block of code for each log file. but only for 1 time effort

Can't create Excel file from Octave script when running from batch file

Using Windows 10, Octave 4.4.1, and Excel 2016, I have an Octave script (call it "MyOctaveProgram.m") that takes data from a text file ("MyTextFile.txt"), which can be loaded with the uigetfile function, but for quicker access, I've created a batch file:
#echo off
C:\Octave\Octave-4.4.1\octave.vbs --force-gui --eval MyOctaveProgram("'%~d0%~p0'","'%~n0'")
cmd /c
The .bat file has the same name as the .txt file, other than the extension.
So far, this all works fine, and I can execute part of MyOctaveProgram.m via the GUI command line, or through the batch file. The difference comes in when I try to use a part of my code that creates a data table in Excel (with the COM interface), using
xls=xlsopen(ExcelFile)
xls=oct2xls(data...)
xls=oct2xls(more data...)
xls=oct2xls(etc...)
xlsclose(xls)
This works fine when I run MyOctaveProgram.m from the GUI command line (choosing MyTextFile.txt with the uigetfile function), but when I try to create the Excel file when running Octave through the batch script above, I get the following message:
(File pointer preserved. Try saving again later...)
This seems to produce no errors, and the session stays open (unlike the GUI, the batch-initiated Octave session will terminate if there's an error), but the Excel file is not created. There are no other Excel windows or tasks open, and I'm not trying to overwrite an existing file. Any advice would be appreciated!

copy into another file while changing some parts batch

I am trying to make a batch file that will copy the contents of one file (with problem characters) that sends an email into another file (also vbs) so as to then run it and send a customizable email (customized by various batch things, my program needs to use batch) So I want to use this command:
type mailersample.vbs>> mailerfinal.vbs
BUT I want to edit certain things. Would I need to go through a variable (problem characters), or would I use the set command, in which case, under which format?

create flat file in ssis package

I'm working on creating a csv export from a SQL Server database and I've been familiar with a process for doing so that admittedly, I've never completely understood. The process involves creating a "template" file, which defines the columns and structure for the file export. Once the "template" file exists, you can use a Data Flow task to fill it and a File System Task to copy it to the final storage destination with whatever file name you'd like (frequently a date/time stamp).
Is there a reason that you can't simply create a file directly, without the intermediate "template" file? I've looked around for a bit and it seems like all the proposed solutions involve connecting to an existing file. I see that there is a "Create File" Usage type for a "File" connection manager, but you can't use it in any File System Task. The only File System Type connection managers you can use relative to a file are "Copy", "Delete", "Move", "Rename", and "Set Attributes".
Is there a way to create a file at package run time and fill it?
The whole point of SSIS is to create a data flow with metadata so that the data can be manipulated - if you just want to go database direct to CSV you are probably better off using bcp (bulk copy program) from the command line. If you want to include it as part of a SSIS package just add an Execute Process Task and add the command line to that. You can dynamically change the included columns or the output file by adding an expression to the task. You could also call bcp though TSQL using an Excute SQL Task.
One other option is to concatenate all your columns in your query inter-spaced with a comma literal and output to a text file with just one very wide column.
For documentation on bcp look here

can we use multiple "cd" commands in a batch file?

I was not able to add multiple change directory commands in a single batch file:
cd C:\abc\def
do something
cd C:\def\ghi
do something
It stops in the second line, and does not come back to execute the third line.
Yes you can.
I am betting that what you're doing in step 2 is calling another batch file, without using the call keyword.

Resources