program automatization - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: program automatization (/thread-12409.html) |
program automatization - clarablanes - Aug-23-2018 Good morning. I'm very new with python but I have been reading and trying a lot of code. My problem is the following: I have to use a binary called Process_Ligand. When I pass the argument (the ligand in this case) it works but I need to use it with hundreds of files. To this end, I have done my first little script that works fine when I use only one file: import os import subprocess import sys cmd = '/usr/share/apps/flexaid_temporal/Process_Ligand -f ligand.pdb' p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)But when I try to automatize to be able to run hundreds of files it doesn't work. This is what I have done: import os import subprocess import sys for file in os.listdir('.'): if file.endswith('pdb'): cmd = '/usr/share/apps/flexaid_temporal/Process_Ligand -f file' p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)Could you help me, please? Thank you in advance. Clara RE: program automatization - Gribouillis - Aug-23-2018 Why do you write stderr=subprocess.PIPE if you don't use the subprocess' error output? I suggestimport os import subprocess import sys cmd = ['/usr/share/apps/flexaid_temporal/Process_Ligand' , '-f'] for file in os.listdir('.'): if file.endswith('.pdb'): subprocess.call(cmd + [file]) RE: program automatization - Prabakaran141 - Aug-23-2018 Hi In your case replace the variable file instead of string 'file'. import os import subprocess import sys for file in os.listdir('.'): if file.endswith('pdb'): cmd = '/usr/share/apps/flexaid_temporal/Process_Ligand -f ' + file p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) RE: program automatization - clarablanes - Aug-23-2018 Thank you both Gribouillis and Prabakaran141. I don't know why I was using stderr. I have been using a lot of this news things for me... I have tried your suggestions and now it works perfect. And so quick in your answer. Thank you very much!!. |