Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error passing double quotes and spaces in install argument (-ia) #245

Closed
PeterMosmans opened this issue Apr 16, 2015 · 20 comments
Closed

Error passing double quotes and spaces in install argument (-ia) #245

PeterMosmans opened this issue Apr 16, 2015 · 20 comments

Comments

@PeterMosmans
Copy link

Hi,

I try to install jre8 with the following install argument: /INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8". The system variable %ProgramFiles% contains a space (c:\Program Files).
From what I understood on the wiki (https://github.com/chocolatey/choco/wiki/CommandsReference#how-to-pass-options--switches ) you can use single quotes instead of double quotes.
However, I tried all sorts of combinations using single quotes, double quotes and escape characters (`), but chocolatey seems to refuse the syntax. When I check the logs I see that the double quotes andor space aren't passed correctly to the Java installer. Some results from the logs:
INSTALLDIRPUBJRE=C:\Program Files\Java\jre8

ConvertFrom-StringData : parsing "C:\Program Files\Java\jre8" - Unrecognized escape sequence \P.

INSTALLDIRPUBJRE=''C:\Program Files\Java\jre8 Error reading config file: "Invalid value" at line 1; char 1

Some (but not all) of the combinations tried (and failed):

-ia '/INSTALLDIRPUBJRE="C:\Program Files\Java\jre8"'
-ia '/INSTALLDIRPUBJRE=''C:\Program Files\Java\jre8'''
-ia '/INSTALLDIRPUBJRE="C:\Program\ Files\Java\jre8"'
-ia '/INSTALLDIRPUBJRE="C:\Program\ Files\Java\jre8"'
-ia '/INSTALLDIRPUBJRE="C:\Program\ Files\Java\jre8"'
-ia /INSTALLDIRPUBJRE="C:\Program\ Files\Java\jre8"
-ia '/INSTALLDIRPUBJRE="C:\Program Files\Java\jre8"'
-ia "/INSTALLDIRPUBJRE=C:\Program Files\Java\jre8"
-ia "/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8""
-ia "/INSTALLDIRPUBJRE=''%ProgramFiles%\Java\jre8''"
-ia '"/INSTALLDIRPUBJRE=''%ProgramFiles%\Java\jre8''"'
-ia "/INSTALLDIRPUBJRE=''%ProgramFiles%\Java\jre8''"
-ia '/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8"'
-ia '/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8"'
-ia '/INSTALLDIRPUBJRE=""%ProgramFiles%\Java\jre8""'
-ia '/INSTALLDIRPUBJRE=''%ProgramFiles%\Java\jre8'''
-ia "/INSTALLDIRPUBJRE=''%ProgramFiles%\Java\jre8''"
-ia ''/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8''
-ia '/INSTALLDIRPUBJRE='';c:\Program;Files\Java\jre8'''

What would be the correct syntax ?

Thanks in advance,

Peter

@gep13
Copy link
Member

gep13 commented Apr 16, 2015

Try the following:

-ia "/INSTALLDIRPUBJRE='C:\Program Files\Java\jre8'"

As per example here:

https://chocolatey.org/packages/VisualStudio2013Ultimate

If that doesn't work, you are going to need to work some magic with the ` (backtick) character, but I can never remember how that works :-) but @ferventcoder should be able to point you in the right direction.

@ferventcoder
Copy link
Member

If you are in cmd.exe you can use just double quotes. If you are in powershell you need to work around it automatically removing the double quotes using backticks.

@ferventcoder
Copy link
Member

Note that the message says, TEST THIS, MAY NOT BE RELEVANT ANYMORE ;)

@ferventcoder
Copy link
Member

@PeterMosmans @gep13 can you verify my update to the documentation as working correctly?

@ferventcoder ferventcoder self-assigned this Apr 16, 2015
@gep13
Copy link
Member

gep13 commented Apr 16, 2015

Looks good to me, not in a position to test it though, hopefully @PeterMosmans can confirm.

Only comment would be to perhaps ditch the code highlighting of the ". Where you show an example of escaping a " with a ` it looks like there is a space between them, due to the code formatting.

I can't think of a way to make that better, without ditching the highlighting though. Any ideas?

@ferventcoder
Copy link
Member

@gep13 fixed.

@PeterMosmans
Copy link
Author

Thanks for the fast responses. When I try it from a command prompt with the syntax
"/INSTALLDIRPUBJRE='%ProgramFiles%\Java\jre8'"
I get the following error:

Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
Root element is missing.
jre8 not installed. An error occurred during installation:
Root element is missing.
Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
Root element is missing.
Root element is missing.

I get the same error when trying the backticked variants:

"/INSTALLDIRPUBJRE=`'%ProgramFiles%\Java\jre8`'"
"/INSTALLDIRPUBJRE=`"%ProgramFiles%\Java\jre8`""

@gep13
Copy link
Member

gep13 commented Apr 17, 2015

Have you tried the latest update to the documentation:

https://github.com/chocolatey/choco/wiki/CommandsReference#how-to-pass-options--switches

Where the backticks are escaping a " not a '?

@PeterMosmans
Copy link
Author

Yes, but that also unfortunately doesn't work:

'/INSTALLDIRPUBJRE=`"%ProgramFiles%\Java\jre8`"'
"/INSTALLDIRPUBJRE=`"%ProgramFiles%\Java\jre8`""
`"/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8"`"
`'/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8"`'

@PeterMosmans
Copy link
Author

Could the quotes/backquotes have somehow "damaged" the installation itself ? Without any options I get the same error message:

>choco install jre8 --force
Chocolatey v0.9.9.4
Installing the following packages:
jre8
By installing you accept licenses for the packages.

jre8 v8.0.40 (forced)
Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
 Root element is missing.
jre8 not installed. An error occurred during installation:
 Root element is missing.
Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
 Root element is missing.
Root element is missing.

And in the logfiles:

jre8 v8.0.40 (forced)

[ERROR] - Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
 Root element is missing.
[ERROR] - jre8 not installed. An error occurred during installation:
 Root element is missing.
[ERROR] - Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
 Root element is missing.
[ERROR] - Root element is missing.

@gep13
Copy link
Member

gep13 commented Apr 17, 2015

Ok, one more variation:

"/INSTALLDIRPUBJRE="%ProgramFiles%\Java\jre8""

NOTE: Only back-ticking the internal quotes, not the external

@PeterMosmans
Copy link
Author

Nope, sorry:

>choco install jre8 -InstallArguments "/INSTALLDIRPUBJRE=`"%ProgramFiles%\Java\jre8`"" --force
Chocolatey v0.9.9.4
Installing the following packages:
jre8;Files\Java\jre8`

...and the same errors

@PeterMosmans
Copy link
Author

Could it be that due to all the tries the registry (?) is broken ?

>choco uninstall jre8
Chocolatey v0.9.9.4
Uninstalling the following packages:
jre8
Which version of jre8 would you like to uninstall?
 1) None [Default - Press Enter]
 2) 8.0.40
2
You selected jre8 v8.0.40
Error deserializing response of type chocolatey.infrastructure.app.domain.Registry:
 Root element is missing.
Root element is missing.

Can I help by copying/uploading relevant logfiles ?

@ferventcoder
Copy link
Member

Yep, upload them to a gist. Make sure to use -dv so we can get lots of information

@PeterMosmans
Copy link
Author

Please find relevant (hopefully) logs here.. https://gist.github.com/PeterMosmans/2d3bdfbae7ace583bd20

I cannot seem to pass double quotes and spaces as install arguments

@ferventcoder
Copy link
Member

@PeterMosmans are you using PowerShell to make these calls?

This is going to get very interesting :/

Command line: choco.exe  install jre8 -dv -ia "/INSTALLDIRPUBJRE=`"C:\Program Files\Java\jre8`"" --force
Received arguments: install jre8 -dv -ia /INSTALLDIRPUBJRE=`C:\Program Files\Java\jre8` --force

InstallArguments='/INSTALLDIRPUBJRE=`C:\Program'
Command line: choco.exe  install jre8 -dv -ia "/INSTALLDIRPUBJRE='C:\Program Files\Java\jre8'" --force
Received arguments: install jre8 -dv -ia /INSTALLDIRPUBJRE='C:\Program Files\Java\jre8' --force

InstallArguments='/INSTALLDIRPUBJRE='C:\Program Files\Java\jre8''

@ferventcoder
Copy link
Member

-ia '/INSTALLDIRPUBJRE="C:\Program Files\Java\jre8"' - will likely work in cmd.exe but not in powershell
-ia "/INSTALLDIRPUBJRE=C:\Program Files\Java\jre8" - will likely work to get it set, but it may not be passed to the installer correctly

-ia "/INSTALLDIRPUBJRE="Program Files\Java\jre8"" - with powershell, everytime you want to keep around a double quote, you need to use the backtick or disable powershell parsing

https://connect.microsoft.com/PowerShell/feedback/details/376207/executing-commands-which-require-quotes-and-variables-is-practically-impossible
tl;dr - use --% before -ia to just pass the args through. Requires POSH v3+

-ia '/INSTALLDIRPUBJRE=""c:\Program Files\Java\jre8\""' - seems to be the ONLY thing that will work in POSH as is. But it doesn't work in cmd.exe.

Command line: "C:\ProgramData\Chocolatey\choco.exe" install bob --noop -ia "/yup=""dude what""" -dv
Received arguments: install bob --noop -ia /yup="dude what" -dv
InstallArguments='/yup="dude what"'

-ia "/INSTALLDIRPUBJRE=""c:\Program Files\Java\jre8\""" - is how it will work in cmd.exe.

Command line: "C:\ProgramData\Chocolatey\choco.exe" install bob --noop -dv -ia="/yup=""dude what"""
Received arguments: install bob --noop -dv -ia=/yup="dude what"
InstallArguments='/yup="dude what"'

@ferventcoder
Copy link
Member

Well that was fun but I have it updated for you. https://github.com/chocolatey/choco/wiki/CommandsReference#how-to-pass-options--switches

What quote values was meant to do was talk about quoting the ENTIRE argument, not just a section. What you really need is how to pass quotes in arguments to be passed through with quotes. I added that section with what we found here.

@PeterMosmans
Copy link
Author

@ferventcoder , thank you so much for helping me with this issue. I should have been clearer that I call chocolatey.exe from within a command shell.
And, lo and behold, when I do so using one doublequote (") around the argument, and two doublequotes ("") around a to-be doublequoted argument, it works.

[DEBUG] - Command line: choco.exe install jre8 -ia "/INSTALLDIRPUBJRE=""C:\Program Files\Java\jre8""" -dv
[DEBUG] - Received arguments: install jre8 -ia /INSTALLDIRPUBJRE="C:\Program Files\Java\jre8" -dv
InstallArguments='/INSTALLDIRPUBJRE="C:\Program Files\Java\jre8"

Thanks once again, especially for clarifying the documentation. At least something good came of it :)

Cheers,

Peter

@ferventcoder
Copy link
Member

For the registry issue - follow #257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants