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

smye
  • 79
  • 1
  • 1
  • 10
  • 2
    Well it seems like you have redirected stdout to the file, so it does not print anything on terminal – magicleon94 Jan 22 '17 at 11:32
  • subprocess.check_call(["python", "trouble.py"]) Should I remove the other parameter? – smye Jan 22 '17 at 11:44
  • anyone else can help? really need this done – smye Jan 22 '17 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. – blubberdiblub Jan 22 '17 at 16:12
  • I don't have any experience with `subprocess` , but giving a very quick look to the documentation I could suggest to try `subprocess.check_call(["python", "trouble.py"], stdout=f,shell=True)` . I don't know exactly what this does though (I couldn't find it). – magicleon94 Jan 22 '17 at 16:24
  • 1
    No sure, but search "Tee". For example: http://stackoverflow.com/questions/2996887/how-to-replicate-tee-behavior-in-python-when-using-subprocess – Onzalo Jan 22 '17 at 18:12

0 Answers0