satya chandra satya chandra - 1 year ago 62
Bash Question

How to store output of a python program in command prompt?

I'm passing run time variable from command prompt to python to execute there (im=n python). Now I want to store the result of python program and use those results back into command prompt. Sample is as follows

set input=
set /P input=Enter Layer Name:%=%
C:\Python27\python.exe F:\xampp\htdocs\flood_publish\ %input%

I'm passing user input string to python program from command prompt as above.
How use the result of python program back into command prompt

Answer Source

Let me know if this helps.

Code of python file (

import sys

print('You passed ',sys.argv[1])

Windows Batch Code (a.bat) :

@echo off

set input=

set /P input=Enter Layer Name:%=%

(python %input%) > tmp.txt

set /P output=<tmp.txt

echo %output%

Output of batch code:

Enter Layer Name:Dinesh
You passed  Dinesh
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download