2

I have a pretty big script and I need to output what the user typed in, and what the response of the program was. Trouble is my big file.

import subprocess with open("output.txt", "wb") as f: subprocess.check_call(["python", "trouble.py"], stdout=f) 

The following code works fine except it doesn't display anything from trouble.py on my command prompt but it still writes to output.txt.

import troube 

When I add this, the program runs correctly (runs as if I was just running the file normally) but doesn't output anything.

How do I go about doing this? Thanks

6
  • 2
    Well it seems like you have redirected stdout to the file, so it does not print anything on terminal Commented Jan 22, 2017 at 11:32
  • subprocess.check_call(["python", "trouble.py"]) Should I remove the other parameter? Commented Jan 22, 2017 at 11:44
  • anyone else can help? really need this done Commented Jan 22, 2017 at 16:04
  • Is it a hard requirement to create the log of the session from a python program? If not, it would likely be easier to just use the script command. Commented Jan 22, 2017 at 16:12
  • 1
    No sure, but search "Tee". For example: stackoverflow.com/questions/2996887/… Commented Jan 22, 2017 at 18:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.