0

I have seen many examples of how to create a file through command line using a static name but I need to get it to show a dynamic name based off of my commands output. What I mean by this is the following:

I run the command npm -v and it returns 6.4.1 I can easily write that out to the inside of a file but I want the filename to be 6.4.1 if that is what the command returns. So if it returns 8.15.1 then the filename would be 8.15.1.

Any idea how to do that? I need this to be able to run on windows 7/10 machines so I can verify versions of npm and resolve version mismatches.

LotPings
  • 7,391
Danny
  • 1

1 Answers1

1

This previous question asked the more general question about the equivalent of bash backticks in the Windows commandline.

For your question, example syntax would be as follows:

for /f "usebackq tokens=*" %i in (`npm -v`) do echo %i > %i

The above would write the output of npm -v to a file with a name of the version of npm.