Calling a python program from python?

I am currently trying to call a non python program from a python script.

I have ~ 1000 files which, when transferred through this program in C ++, will generate ~ 1000 outputs. Each output file must have a different name.

The command that I want to run is as follows:

program_name -input -output -o1 -o2 -o3

To date, I have tried:

import os

cwd = os.getcwd()

files = os.listdir(cwd)

required_files = []

for i in file:
    if i.endswith('.ttp'):
         required_files.append(i)

So, I have an array of required files. My problem is how can I iterate over the array for each record, pass it to the above command (program_name) as an argument and specify a unique output identifier for each file?

+4
source share
1 answer

subprocess :

import os
import subprocess

cwd = os.getcwd()

for i in os.listdir(cwd):
    if i.endswith('.ttp'):
        o = i + "-out"
        p = subprocess.call(["program_name", "-input", i, "-output", o])
+10

All Articles