skip to Main Content

I am trying to make the following command work in Powershell:

mvn -Dhttp.nonProxyHosts='xxx.xxx.*|*.example.com|*.example2.com|localhost|127.0.0.1' -DskipTests clean install

This command works fine in Ubuntu, but I unfortunately need a version working in Powershell. This command keeps failing with the message:

The command "*.example.com" is either misspelled or could not be found

So clearly, the pipes are interpreted as pipes.

I have tried:

  • Escaping the pipes with backslashes , backticks ` and circumflexes ^
  • Enclosing the whole argument with double quotes (turns the argument blue, still same error):
mvn "-Dhttp.nonProxyHosts='xxx.xxx.*|*.example.com|*.example2.com|localhost|127.0.0.1'" "-DskipTests" clean install
  • Enclosing the argument with double quotes and trying all of the escape characters above.

None of these had any effect.

I have no idea how to get Powershell to ignore the pipes inside of the argument. Powershell version is PSVersion 5.1.19041.3031.

2

Answers


  1. Chosen as BEST ANSWER

    A lot of trial and error later, I got this to work:

    mvn '-Dhttp.nonProxyHosts="xxx.xxx.*|*.example.com|*.example2.com|localhost|127.0.0.1"' "-DskipTests" clean install
    

    The single quotes from the command working in Ubuntu must be replaced with double quotes, and the whole Maven argument must be enclosed in single quotes. That way, the pipes are apparently interpreted as part of the string and the double quotes are kept. I could not get this to work with single quotes in the argument, that gave me the escaping problem again.

    I would have liked to keep the single quotes in the maven argument, but this seems to work, too.


  2. tl;dr

    You’re seeing a long-standing bug in PowerShell’s parameter binder when calling external programs, present up to at least v7.3.6, affecting --prefixed arguments that also contain . – see GitHub issue #6291.

    The simplest workaround is to `-escape the initial -:

    # Note the ` char.
    mvn `-Dhttp.nonProxyHosts='xxx.xxx.*|*.example.com|*.example2.com|localhost|127.0.0.1' -DskipTests clean install
    

    For background information and alternative workarounds, see this answer.


    It isn’t obvious, but it isn’t pipes (|) or quoting that are the problem:

    • PowerShell, like POSIX-compatible shells such as Bash, supports '...' strings, i.e. verbatim (single-quoted) strings, inside of which no characters have special meaning (except that – unlike in POSIX-compatible shells – you can escape embedded ' chars. as '').

    • Instead, it was the specific manifestation of the aforementioned bug that caused the problem: PowerShell unexpectedly broke your single -D... argument (after removal of the single quotes) in two, namely at the first ., so that mvn ended up seeing the following verbatim arguments, which presumably caused the error you saw.

      • -Dhttp
      • .nonProxyHosts=xxx.xxx.*|*.example.com|*.example2.com|localhost|127.0.0.1
      • -DskipTests
      • clean
      • install
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search