简体   繁体   中英

Running another program using Python

I have a program that processes files and returns another file as output. When I am running it in cmd I first set the path: "cd c:\\program" and then set it to process the file located in the program folder: "program test.txt". I would like a python program to do it for me using the subprocess module, but I can't get it to work.

I have read the related posts and I know it should be a no-brainer, but as a novice I haven't been able to figure it out. Help greatly appriciated.

Here is one example of the code I tried. It runs, but doesn't produce any results.

import subprocess

textfile = 'c:\program\test.txt'
programPath = r'C:\program\program.exe'
subprocess.Popen([programPath, textfile])

You forgot to prepend r to textfile 's literal:

textfile = r'c:\program\test.txt'

( \\t is a tab character. Next time, please include any error messages in the post as well.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM