I need to have some help.
I used python33 on Windows OS.
I want result it.
Call Python in Batch File.
( python Testing.py %arg1% %arg2%
)
python is do return string value.
( return('END') or exit('END')
)
and I want set BatchFile Variable
( SET returnValue = python Testing.py %arg1% %arg2%
)
and Use Variable %returnValue%
I tried search key word. 'python return value to batch file'
I found this hint.
( Python ) sys.exit(number)
So Called %ErrorLevel% in BatchFile.
But this Sample can integer. don't apply string.
Of course, Python can make string in file. and Batch File can Load File .
or Also Environment Variable can.
But I want different method.
I want just Python do Return value and How use the Return Value in Batch File .
How can I do that?
As far I have understood your question. You would like to execute a python script from a batch file and then would like to save the output of the python script to a variable in the batch file.
Here is my way (there could be a better way to do this). I am simply executing the python script test2.py
from my batch file and then I save the output of the python script to a temporary file called as Output
later I read this file to a batch file variable named as MYVAR
and then I am deleting the temp file Output
.
The batch code is provided below:
@ECHO OFF
test2.py > Output
SET /p MYVAR=<Output
ECHO %MYVAR%
PAUSE
DEL Output
The python file test2.py
contains the following code:
print "Python"
The batch file & the python file are in the same directory!
Output:
Upon executing the batch file you shall see this in the console:
Python
Press any key to continue . . .
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With