I am using powershell 7.4.1 on Linux and Windows.
And I used following commands to get the current target version of my maven project.
$version = mvn help:evaluate -Dexpression='project.version' -q -DforceStdout
or
$version = mvn exec:exec -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive -q
if I print the $version it looks like that they are working on both platform and are returning 2.68.0-SNAPSHOT
However I experienced some problems on my Linux system. So after digging I found the cause in the commands above. Because if I print the output as hex values to what that string contains.
I get on Linux
32 2E 36 38 2E 30 2D 53 4E 41 50 53 48 4F 54 20 1B 5B 30 6D
on Windows
32 2E 36 38 2E 30 2D 53 4E 41 50 53 48 4F 54
So does anybody know why there are 20 1B 5B 30 6D this additional characters on my Linux system. And how can I get rid of them (except replacing them afterwards)?
The string you're receiving contains ANSI/VT escape sequences, which are typically used for producing colored terminal output.
If the intent is to receive data only, as in your case, these escape sequences are undesired.
If available, it is best to ask an external program such as
mvnnot to produce colored output to begin with.According to the Maven CLI Options Reference, you can use
-B(or--batch-mode) to disable coloring;[1] e.g.:.in the unquoted part following the parameter name must have their initial-escaped as`-.For instance,
-Dexec.executable='echo'must be passed as`-Dexec.executable='echo'- see this answer for background information.If not, you can remove these escape sequences with the help of the
[System.Management.Automation.Internal.StringDecorated], available in PowerShell (Core) 7+ only (v7.2+):A simple example: The sample string contains escape sequences that render the word "green" in green; the
.ToString('PlainText')method call strips (removes) these escape sequences.[1] The documentation link is to the current stable version of
mvn(via a/current/segment in the URL, which turns into the concrete version number in the browser), which is v3.9.6 as of this writing. The same page is available down to version 3.1.0 and shows the-B(--batch-mode) option too; whether even earlier versions also support it, I don't know -mvn --helpmay reveal that.