Page 1 of 1 1
Topic Options
#213944 - 2020-11-25 04:43 PM Passing path with spaces inside quotes still not working - me going crazy
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213945 - 2020-11-25 06:16 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Maybe extra double quote in red...

'%comspec% /c "D:\Folder\Folder with spaces\Tools\dtexec.exe" /file "'

Top
#213946 - 2020-11-25 06:26 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
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 + '"'

Top
#213947 - 2020-11-27 10:31 AM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.


Edited by Mart (2020-11-27 10:35 AM)
Edit Reason: Added comment.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213948 - 2020-11-27 03:28 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213949 - 2020-11-27 04:19 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
 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?

Top
#213950 - 2020-11-27 05:00 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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"
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213951 - 2020-11-27 05:11 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
hmmm, nothing seems abnormal about that. Have you tried running everything past the cmd.exe /c to see if it comes back clean?
Top
#213952 - 2020-11-27 06:40 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Allen]
Henriques Offline
Fresh Scripter

Registered: 2007-09-13
Posts: 43
What about the length being 263 characters
Top
#213953 - 2020-11-28 06:47 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
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 + '""'
_________________________
Christophe

Top
#213954 - 2020-11-30 09:34 AM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213955 - 2020-11-30 09:34 AM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Henriques]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: Henriques
What about the length being 263 characters


Hmmm.... did not think of that. I'll try a shorter path.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213957 - 2020-11-30 10:51 AM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: ChristopheM]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 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!
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213958 - 2020-12-03 09:27 AM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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
Top
#213959 - 2020-12-03 12:48 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: NTDOC]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213979 - 2021-03-03 11:22 PM Re: Passing path with spaces inside quotes still not working - me going crazy [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
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.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org