Ross Hudson
Ross Hudson

Reputation: 83

Importing variables from python into a batch file

I want to be able to transfer a variable set in python to be used in a batch file. Is this possible?

Upvotes: 0

Views: 767

Answers (2)

Imran
Imran

Reputation: 91029

Set environment variable in your python script, and use that variable in your batch file

>>> import os
>>> os.environ['x'] = 'a'
>>> os.system('echo %x%')
# prints 'a'

Upvotes: 1

Mihai8
Mihai8

Reputation: 3147

Try to use os.putenv after import of os module. Also, take a look on PyBat.

Upvotes: 1

Related Questions