Search code examples
javapowershelljbosswildfly

JBoss PowerShell client add module path with space


I am trying to add a module to a WildFly instance using the JBoss PowerShell client, but it fails when the path to the module contains a space.

I have tried wrapping the path in single and double-quotes to no avail.


List of use cases tested:

  1. Without quotes
  2. Using single-quotes
  3. Using double-quotes
  4. Escaping the space with a backslash (\)
  5. Escaping space with backtick (`)
  6. Using double-quotes inside a single-quoted command
  7. Escaping the inner double-quotes with backtick (`)
  8. Escaping inner double-quotes with backslash (\)
  9. Using double double-quotes ("")
  10. Escaping inner single quotes with backslash (\) in a double-quoted command

Examples

1. Without quotes

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=C:/module directory/sqljdbc42.jar"

Error message

The command accepts 1 unnamed argument(s) but received: [add, directory/sqljdbc42.jar]


2. Using single-quotes

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources='C:/module directory/sqljdbc42.jar'"

Error message

The command accepts 1 unnamed argument(s) but received: [add, directory/sqljdbc42.jar']


3. Using double-quotes

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources="C:/module directory/sqljdbc42.jar""

Error message

'directory\sqljdbc42.jar' is assumed to be a command(s) but the commands to execute have been specified by another argument: [module add --name=mssql.jdbc --resources=C:\module]


4. Escaping the space with a backslash (\)

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=C:/module\ directory/sqljdbc42.jar

Error message

Failed to locate C:\module\ directory\sqljdbc42.jar, if you defined a nonexistent resource on purpose you should use the --allow-nonexistent-resources option


5. Escaping space with backtick (`)

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=C:/module` directory/sqljdbc42.jar"

Error message

The command accepts 1 unnamed argument(s) but received: [add, directory/sqljdbc42.jar]


6. Using double-quotes inside a single-quoted command

JBoss client command

.\jboss-cli.ps1 --connect --command='module add --name=mssql.jdbc --resources="C:/module directory/sqljdbc42.jar"'

Error message

'directory/sqljdbc42.jar' is assumed to be a command(s) but the commands to execute have been specified by another argument: [module add --name=mssql.jdbc --resources=C:/module]


7. Escaping the inner double-quotes with backtick (`)

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=`"C:/module directory/sqljdbc42.jar`""

Error message

'directory/sqljdbc42.jar' is assumed to be a command(s) but the commands to execute have been specified by another argument: [module add --name=mssql.jdbc --resources=C:/module]


8. Escaping inner double-quotes with backslash (\)

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=\"C:/module directory/sqljdbc42.jar\""

Error message

'directory/sqljdbc42.jar\' is assumed to be a command(s) but the commands to execute have been specified by another argument: [module add --name=mssql.jdbc --resources=\C:/module]


9. Using double double-quotes ("")

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=""C:/module directory/sqljdbc42.jar"""

Error message

'directory/sqljdbc42.jar' is assumed to be a command(s) but the commands to execute have been specified by another argument: [module add --name=mssql.jdbc --resources=C:/module]


10. Escaping inner single quotes with backslash (\) in a double-quoted command

JBoss client command

.\jboss-cli.ps1 --connect --command="module add --name=mssql.jdbc --resources=\'C:/module directory/sqljdbc42.jar\'"

Error message

The command accepts 1 unnamed argument(s) but received: [add, 'C:/module, directory/sqljdbc42.jar\']


Solution

  • The correct format is to escape double-quotes inside a single-quoted command.

    .\jboss-cli.ps1 --connect --command='module add --name=mssql.jdbc --resources=\"C:/module directory/sqljdbc42.jar\"'
    

    Thank you @Aaron for your help.