Q:

Linux Command for Perl in Python

I am trying to this Linux command for Perl (v5.10.1) in Python (v2.6)
perl tilt.pl *.pdb > final.txt

What do I do so that I can apply the Perl script to every PDB file, examples would be best?
my current script is this:
import shlex, subprocess
arg_str = "perl tilt.pl frames > final.txt"
arg = shlex.split(arg_str)

print(arg)

import os
framespdb = os.listdir("prac_frames")

for frames in framespdb:
        subprocess.Popen(arg, stdout=True)

A:

You can use shell=True
BTW: I think you try to put variable frames in place of text frames in command so I use %s and line % frames to do this.
import os
import subprocess

line = "perl tilt.pl %s > final.txt"

framespdb = os.listdir("prac_frames")

for frames in framespdb:
    cmd = line % frames
    print(cmd)
    subprocess.Popen(cmd, shell=True)

EDIT: if you need results in different files you can use again %s to add unique filename to command - for example:
import os
import subprocess

line = "perl tilt.pl %s > final-%s.txt" # second `%s`

framespdb = os.listdir("prac_frames")

for frames in framespdb:
    cmd = line % (frames, frames) # second `frames`
    print(cmd)
    subprocess.Popen(cmd, shell=True)

EDIT: normally in shell you can send result on screen or redirect it to file > file.txt. To get text on screen and save it in file you need shell command tee and python command subprocess.check_output():
import os
import subprocess

line = "perl tilt.pl %s | tee final-%s.txt"

framespdb = os.listdir("prac_frames")

for frames in framespdb:
    cmd = line % (frames, frames)
    print(cmd)
    output = subprocess.check_output(cmd, shell=True)
    print 'output:', output

