0

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])
4
  • 8
    Please show what you've tried and what went wrong: program + error message. Commented Mar 7, 2012 at 12:47
  • What do you mean by "It runs, but doesn't produce any results"? How can you tell it's running? How do you expect results to be produced? Commented Mar 7, 2012 at 13:23
  • What I meant is that it does not produce an error. Also it does not produce the desired results. Commented Mar 7, 2012 at 13:25
  • Maybe Popen is not what you want. You might want to try subprocess.check_call. Commented Mar 7, 2012 at 13:29

1 Answer 1

3

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.)

Sign up to request clarification or add additional context in comments.

3 Comments

Unless I'm mistaken, there wouldn't typically be any error message from this issue. But prepending r is right
@DavidRobinson: program.exe would (hopefully) give an error message.
Thank you. Embarrasingly it solves the problem. (the mistake didn't produce an error though - thats why I thought I was more conceptually wrong here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.