0

I want to be able to set a version number in a Powershell/CMD argument that is stored in a file. So let's say i have a long powershell/cmd command that has this argument in it py -m non_important_script --file-version={*get value from file*}

How would i get the version number that is stored in a file called version.py with one row of text in it:

__version__ = "1.2.0"

Basically i don't want to update this argument manually every time. It would be nice if i could always paste the same command into Powershell/CMD and it would put in the version number on it's own.

So far i've tried this py -m non_important_script --file-version=(Select-String -Path .\version.py -Pattern "\d.\d.\d").Matches.Groups[0].value, but it doesn't work and gives this error from the non_important_script:

FATAL:
Error, specify only one positional argument unless "--run" is specified to
pass them to the compiled program execution.
0

1 Answer 1

0

A working Windows CMD solution suggested by Mofi is:

for /F "tokens=1* delims== " %I in (.\version.py) do if /I "%~I" == "__version__" py.exe -m non_important_script --file-version=%J

I managed to figure out a PowerShell solution as well continuing from what I already had in my question hoping there was some easy way to make it work and it turns out there was.

There must be created a variable like this and then end with a semicolon to allow the second command sequence to use the value of the variable:

$version = (Select-String -Path .\version.py -Pattern "\d.\d.\d").Matches.Groups[0].value ; py -m non_important_script --file-version=$version
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.