windows - How to execute command line in a python loop? -


I am trying to determine the best way to execute something in the command line using Python. I have completed it on personal files, however, I am trying to determine the best way to do this multiple times with many different files, I am not sure that I should make a batch file and then execute it in the command Or, if I'm missing something in my code If newbie signifies I apologize in advance. The script below gives a returncode of 1 when I use a loop, but when 0 is not in the loop. What is the best way to work at hand?

  def Checkout Out (Command, Console): If Console == Correct: Process = Sub Process Popin (command) Other: process = subprosec Popin (command, shell = true, standout = subprocess PIPE, stderr = subprocess.STDOUT, universal_newlines = true) output, error = process.communicate () returncode = process.poll () returncode, output, fileList.split (";" ) Error for File: ... code ReturnCode! = 0: print ("Process Fail") sys.exit ()   

Edit: To create command string ... return code, output, error = check_output (command, an example The command string looks like this:

C: \ path \ executable. Exe -i C: \ path \ to \ input.ext -o C: \ path \ to \ output.ext << / Div>

Try using the command module (available only before Python 3)

  & gt; & gt; Import Order & gt; & gt; & gt; Command .getstatusoutput ('ls / bin / ls') (0, '/ bin / ls')  < / pre> 

Your code may look like

  import command definde command (command): rate, output = commands.gettestatput (command) if rate! = 0: sys.stderr Return command for file in fileList.split (';'): CommandSet = "#" Create a command string if run command (print command): print ("command '% s' failed" % Command Ster) "sys.exit (1)   

You are not completely clear that problem which you are trying to solve if I guess Be seen why your order is failing in the loop, perhaps by the way you handle console = wrong case.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -