Tuesday, March 20, 2012

Calling commands from the cmd prompt

I have a series of commands that I need to run which decrypt, unzip, and rename

They are all one line commands when entered on the cmd prompt, is there an easy way to do this in ssis or should i write an exe and call them from there?

Thanks

Look at the Execute Process Task.

Frank

|||Yes, but the execute process task will execute a program. Granted I could make that program cmd.exe, I stuck on how to make an execute process task that will open up cmd and make the calls that I want. I could write a .exe file that that I could then put in the execute process task, I'm just curious if there's a way to do it w/ out writing my own script.exe file.

Thanks|||

Yeah Frank is correct on this one. The execute Process task shells to a command prompt automatically for you an dissues pkunzip or whatever tool you're using to decompress the file. The Script task in this case would be an overkill. You can make the Execute Process task typically call PKunzip.exe in the command (make sure you point to the full path) then the argument would be the file name and any switches for override.

--Brian

|||I'm using gzip to decompress files.

the command I'd like to run is gzip -dc filetounzip > filenametosaveto

I'm having no problem running everything before the ">" character. This normally pipes the output to location filetosave to. Without the filenametosave to it dumps the output to the standard out.
I tried to put the filenametosave to in a variable in the standardoutputvariable property w/ no avail. The reason I'm using gzip is because I'm unzipping a .gz file.

Thanks|||

you should use an expression for your argument property.

Frank

|||I have, when I do I get the following error

Error: 0xC0029151 at Positions Unzip Task, Execute Process Task: In Executing "C:\Program Files\GNU\Gzip\gzip.exe" "-dc F:\location\20060831.filename.gz.file > F:\location\test" at "", The process exit code was "1" while the expected was "0".
Task failed: Positions Unzip Task

The expression evaluates to the following.
-dc F:\location\20060831.filename.gz.file > F:\location\test

I'm stuck...|||

have you verified that the command you need to run can run from a dos prompt? you might want to try typing the command into a dos prompt to verify that it runs. that way, you can figure out if it's a gzip issue or an SSIS issue...

|||It works perfectly when I enter the command on the dos prompt

gzip -dc somefile.gz > somefile.txt

And when I enter

gzip -dc somefile.gz

The program executes properly and dumps the entire export of the file to the standard out and I see a large unzipped text file appear for a second in the cmd window. The problem arises when the > character appears.|||What about calling a simple command like ren (rename)

ren oldfilename.txt newfilename.txt

It's not possible to select cmd.exe as the executable and enter the rest as arguments. Any Thoughts?

Thanks|||

The File System task would be the better task to use to rename a file. you could use the execute process task with the following:

executable: C:\WINDOWS\system32\cmd.exe

arguments: /C ren testfile.txt renamed.txt

Frank

No comments:

Post a Comment