Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
program automatization
#1
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
Reply
#2
Why do you write stderr=subprocess.PIPE if you don't use the subprocess' error output? I suggest
import 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])
Reply
#3
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)
Reply
#4
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!!.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020