Sub-process stdout using file object not working when using PyCharm
Hi all,
I have a simple snippet of Python program which correctly works using IDLE or Windows's CMD. But I am not able to make it work using PyCharm. The goal is to run nc.exe
(to get logs from a device under test) using subprocess.Popen
and to redirect the sub-process stdout
to a log file. Below is the python code:
import subprocess
nc_ex = r"C:\Users\lambda\Desktop\Tool\nc.exe"
ipaddr = "192.168.51.202"
port = "3001"
log_file = open("test_file.bin", "wb")
p = subprocess.Popen([nc_ex, ipaddr, port], stdout=log_file)
Using IDLE or CMD, the log file is correctly growing with logs received. Using PyCharm the log file remains empty. I tried to deal with subprocess.Popen
arguments value (creationflags=subprocess.CREATE_NEW_CONSOLE), look for Pycharm configuration, follow this topic subprocess not working when running inside pycharm , but I can't figure it out. Does anyone has a solution to this strange behavior?
Thanks.
Please sign in to leave a comment.
Hello,
Please try to open the run configuration for your script, toggle the option "Emulate terminal in output console," and try to rerun your script.