0

I want to print version of e.g. Packer in cmd. This works with packer --version. Unfortunately this prints the version number only - but not the name of the tool. This is the case with some other tools (e.g. VirtualBox, etc.), too.

C:\_TEMP λ packer --version 0.10.1 λ vboxmanage --version 5.1.4r110228

So my idea was to do somethink like echo Packer & packer --version but this prints in two lines:

C:\_TEMP λ echo Packer & packer --version Packer 0.10.1

Now, how can I print Name + version number in one line? So that the result looks like:

Packer 0.10.1 Virtualbox 5.1.4r110228

Wlad
  • 2,866
  • 3
  • 28
  • 42

2 Answers2

0

Assign the result of version to an environment variable

for /f %a in ('packer --version') do set VERSION=%a

then echo what you like

echo packer %VERSION%

Explanation:

  • You're looping over the output of packer --version (there's only 1 line though so VERSION gets set only one)
  • if you need only one token from the line then you can specify eg "tokens=2" for the second space delimited token.

NOTE: These commands work from the command line. To use in a batch file turn %a into %%a.

FloatingKiwi
  • 4,408
  • 1
  • 17
  • 41
  • Damn, that's so much work for such a little thing to achieve :))) but I guess there is no easier way(?). Thank you for additional explanation and the NOTE, it's very good - I am sure I would have run into it. – Wlad Sep 07 '16 at 16:06
0

you can also (ab)use set /p for that (see for example here):

<nul set /p "=Packer: "
packer --version
<nul set /p "=VirtualBox: "
vboxmanage --version
Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91