|
|
|||||||
I've been pulling my hair out today about this one. We have a whole bunch of SSIS packages (.DTSX files) that can be ran from the command line using dtexec.exe. There are spaces in the path to the package, the path to dtexec.exe and the path to the output file. To get around this I wrapped the paths including the file names in quotes so the spaces are preserved. Somehow I'm missing something because the command below does not work. I tried so many different ways to add the quotes all without success. Code: ... $shellline = '%comspec% /c "D:\Folder\Folder with spaces\Tools\dtexec.exe" /file "' + $ssispackage + '" /de MySecretPassword >"' + $ssisoutput + '"' ... When I display $shellline it shows the correct paths with quotes and all but when I run the script it says "D:\Folder\Folder is not recognized as an internal or external command, operable program or batch file" so it cuts the command at the first space. Running it without %comspec% /c works fine but I need this to be able to redirect the output of dtexec.exe to a text file. How do I properly pass the spaces to %comspec%? I thought I knew this but I guess not. I double and triple checked all variables and they all show the correct path and filename with quotes to preserve the spaces. Have I been staring at this to long and going blind for the obvious issue or am I just going crazy? |
||||||||
|
|
|||||||
Maybe extra double quote in red... '%comspec% /c "D:\Folder\Folder with spaces\Tools\dtexec.exe" /file "' |
||||||||
|
|
|||||||
Think I see what you are trying to do. See if this works any better Code: $shell='%comspec% /c "D:\Folder\Folder with spaces\Tools\dtexec.exe" /file ' + '"' + $ssispackage + '"' + ' /de MySecretPassword >' + '"' + $ssisoutput + '"' |
||||||||
|
|
|||||||
Thanks for the suggestions Allen. Both gave the me the exact same results that I had with my line. I think the issue is with dtexec.exe stripping some quotes and then cutting the path at the first space. I'll try some more and see what comes up. If it all fails we might need to live without the output from dtexec.exe in a text file Would be great to have in case of issues but one cannot do what is not possible. I'll try some more and post an update here. Stripping out the spaces and use a minus or underscore instead would also be a possible option. |
||||||||
|
|
|||||||
Getting way to much frustration from this. I need to take care of my heart and do not drive myself crazy trying to figure this out so I stripped the spaces out of the path and replaced the by a minus - sign and this works fine. Not so nice but it works and that is more important at the moment. Now it is time for a beer........or two. |
||||||||
|
|
|||||||
Quote: Running it without %comspec% /c works fine but I need this to be able to redirect the output of dtexec.exe to a text file This makes me think we can get it to work. Can you run one of your scripts that outputs the value of $shell so we can see what it looks like? |
||||||||
|
|
|||||||
Sure. $shell looks like this Quote: C:\Windows\system32\cmd.exe /c "D:\Folder\Folder with spaces\Tools\dtexec.exe" /file "D:\folder\folder with spaces\SSISPackages\office\Daily\package.dtsx" /de MySecretPassword >"D:\Folder\Folder with spaces\SSISPackages\office\Daily\Output\SSISOutput_Package.txt" |
||||||||
|
|
|||||||
hmmm, nothing seems abnormal about that. Have you tried running everything past the cmd.exe /c to see if it comes back clean? |
||||||||
|
|
|||||||
What about the length being 263 characters |
||||||||
|
|
|||||||
Hello, this a problem due to file redirection. Your first code is near the solution. Add a double quote after /c and at the end of the command Code: $shellline = '%comspec% /c ""D:\Folder\Folder with spaces\Tools\dtexec.exe" /file "' + $ssispackage + '" /de MySecretPassword >"' + $ssisoutput + '""' |
||||||||
|
|
|||||||
Originally Posted By: Allen hmmm, nothing seems abnormal about that. Have you tried running everything past the cmd.exe /c to see if it comes back clean? Yes I did but that works fine. When started from the script the redirection needs to be removed because you need CDM for that but it works just fine with redirection when copied into a command window and without redirection and cmd from the script. |
||||||||
|
|
|||||||
Originally Posted By: Henriques What about the length being 263 characters Hmmm.... did not think of that. I'll try a shorter path. |
||||||||
|
|
|||||||
Originally Posted By: ChristopheM Hello, this a problem due to file redirection. Your first code is near the solution. Add a double quote after /c and at the end of the command Code: $shellline = '%comspec% /c ""D:\Folder\Folder with spaces\Tools\dtexec.exe" /file "' + $ssispackage + '" /de MySecretPassword >"' + $ssisoutput + '""' You are the man Christophe! I copied everything back to the path with spaces and it works great. No issues or error messages anymore. It looks unnatural to me but it works just fine. Thank you so much! |
||||||||
|
|
|||||||
That's the great kind of collaboration we're missing today. Very little discussions going on like this anymore. Glad to see and glad you got a solution Mart |
||||||||
|
|
|||||||
I've been here for a few years (18-ish) now and I also miss this kind of collaboration. But hey, times change and people move on. Other languages have picked up a lot of users I guess. 18 years ago there was no PowerShell for example. Still using Kix and still happy with it bit I do see PowerShell taking up a large portion of the scripting at our company. |
||||||||
|
|
|||||||
Just had to do something very similar to this, and for the life of me, I don't remember ever having to use the double quote trick with %comspec%. Glad this thread was here. I was about to pull my hair out. |