Reading Text From A Bat File In To Python
Is it possible to read a line from a batch file in to a python script? I have a .bat file that contains the following: @echo off rem generated from template Set A_version= 9.0.0
Solution 1:
for line inopen('name.bat', 'r'):
if'A_version'in line:
A_version = line.split('=')[-1].strip()
break
This will search for the string, assign the value to a variable of the same name and break out of the loop in case the variable is referenced later in the bat, we don't need that.
Solution 2:
Try something like this:
withopen('file.bat', 'r') as file:
for line in file:
if'A_version'in line:
value = line.split('=')[1].strip()
Post a Comment for "Reading Text From A Bat File In To Python"