How to store output of a python program in command prompt?
<p>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</p>

<pre><code>set input=
set /P input=Enter Layer Name:%=%
C:\Python27\python.exe F:\xampp\htdocs\flood_publish\projection_raster.py %input%
</code></pre>

<p>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</p>

<p>It is depending on the case. If your Python code is exiting a value (with <code>exit(&lt;returncode&gt;)</code>), you can retrieve it from the <code>%ERRORLEVEL%</code> environment variable.</p>

<pre><code>&lt;yourpythoncommand&gt;
echo Return code: %ERRORLEVEL%
</code></pre>

<p>If you are willing to capture and process the standard output, you need to use a <code>FOR</code> loop:</p>

<pre><code>FOR /F "delims=" %%I IN ('&lt;yourpythoncall&gt;') DO CALL :processit %%I
GOTO :EOF

:processit
echo Do something with %1
GOTO :EOF
</code></pre>

<p>Now, if you don't want to process the output line by line, the easiest is to redirect the output to a temporary file.</p>

<pre><code>&lt;yourpythoncommand&gt; &gt;%TEMP%\mytempfile.txt
&lt;do something with %TEMP%\mytempfile.txt&gt;
del %TEMP%\mytempfile.txt
</code></pre>

python shell cmd runtime parameter-passing