I am trying to write a python script (in windows) that runs a batch file and will output the command line output of this batch file as input. In a batch file, processes that I do not have access to are executed, and produces results based on the success of these processes. I would like to take these messages from a batch file and use them in a python script. Anyone have any ideas on how to do this?
import subprocess output= subprocess.Popen( ("c:\\bin\\batch.bat", "an_argument", "another_argument"), stdout=subprocess.PIPE).stdout for line in output: # do your work here output.close()
Please note that it is preferable to run the batch file with " @echo off".
@echo off
python script, test.bat :
import os fh = os.popen("test.bat") output = fh.read() print "This is the output of test.bat:", output fh.close()
test.bat:
@echo off echo "This is test.bat"
Try executing subprocess.Popen (). It allows you to redirect stdout and stderr to files.
Source: https://habr.com/ru/post/1707979/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1707974/windows-command-line-tool-analagous-to-unx-tail-command&usg=ALkJrhjgMt1DgWCqlqcbe30nP766ywMb0QSyntax highlighting for several languages ββin one file: StatWeave / SAS / LaTeX - editorDraw 2D with SlimDX - c #The difference between h1 em and h1> em - cssHow to list all locations in MapPoint 2009 in PlaceCategory using .NET (C # or VB.NET)? - .net.Net of several event handlers for an event that returns a value - event-handlingStandard .Net Dictionary. - dictionarySearch for approximate local highs with noisy data in Matlab - matlabUse C # regex to convert shell to string - stringIs there a cross browser way to expand text when css is clicked? - javascriptAll Articles