0

I would like to know how to run a Python command inside a batch file and store the result in an enviroment variable. The aim is to carry out several floating point operations, as batch files only allow integer operations.

I need to read some strings (real numbers) using the bat file, then pass those strings to python variables, convert the strings into doubles with python, carry out several simple operations (multiplications and divisions) and finally store the results of the operations in new batch variables.

Adr
  • 11
  • 1
  • 4
  • Why use batch at all? You should consider porting your batch stuff to Python. It might be easier and much more flexible – Svend Feldt Feb 25 '16 at 09:21
  • You have to start python from a batch file that also calls a batch file before exiting, then deletes it. Python has to write that batch file before exiting. The batch file contains `set =` commands. –  Feb 25 '16 at 09:24
  • may be [this is](http://stackoverflow.com/questions/16203629/batch-assign-command-output-to-variable) what you need? – npocmaka Feb 25 '16 at 09:31
  • Thanks for your replies! I still do not manage to make it work. However, I have thought of using Powershell inside the *.bat file. For example, if I needed to substract two variables `%v1%` and `%v2%` I would do something like `powershell %v1% - %v2%`. Do you know how can I store the result in a new enviroment variable? – Adr Feb 26 '16 at 09:29

1 Answers1

2

you need to add python to your system path and then you can run python script via the batch with the following command:

python script.py args
Community
  • 1
  • 1
Isdj
  • 1,835
  • 1
  • 18
  • 36