HI All!
I need to have some help. I have a python function name is abc.py and variable is declared in abc.py, variable name is 'uname'. How can i call variable name 'uname' of abc.py in my batch file name testing.bat and get uname value in my batch testing.bat file?

Best Regards
Sarfraz

One solution would be putenv.
On linux:
abc.py:

import os

uname="Some uname value"
os.putenv("UNAME",uname)
os.system("./test.sh")

test.sh:

echo $UNAME

Other solutions:
- communication file
- os.environ
- database
- parsing .py file and getting out the variable from the batch file

The last version would be:
test.bat

python -m abc -c print uname

Hi Slate
Thanks for help. i tried all 3 solutions but they are not working. i am using Windows 2003 as my OS and need to work on batch file and python script.
Do you have any more idea?

Best Regards
Sarfraz

Please include the error messages. The variable must of course be global variable in the python file. At least saving the value to text file to be read by the script should work.

Please include the error messages. The variable must of course be global variable in the python file. At least saving the value to text file to be read by the script should work.

HI Tonyjv
I write in abc.py

import os
pname="fk12345"
os.putenv("FK_DBO_PASS",pname)
os.system("test.bat")

And then i write in my test.bat BATCH file

@echo off
python setev.py
echo $FK_DBO_PASS

And it gives me this result
C:\Python26>test.
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS

c:\python26>

My goal is to set environment variable in python function. but os.environ is not working for this purpose. so i want to get value of variable in python function into my batch file and then i will use that value to set environment variable in batch file.
Can you please guide more on it. Thanks
Regards
Sarfraz

My recommendations:

Try write a bat file, that can display any environment variable...
Then write a bat file, that runs a predefined python script. Not just any.
Read about recursion, and independent thinking.....

This article has been dead for over six months. Start a new discussion instead.