Hide CMD call window - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Hide CMD call window (/thread-41964.html) |
Hide CMD call window - tester_V - Apr-15-2024 Greetings! Running my script every hour on a windows machine. The script has a “arp-a” cmd call and a window pops up that is very annoying . How I can suppress the pop up window? code: with open(fl,'w') as e : cmd = "arp -a" returned_output = subprocess.check_output(cmd) ln = returned_output.decode("utf-8") ln=ln.strip() print(ln) e.write(ln)Thank you. RE: Hide CMD call window - Gribouillis - Apr-15-2024 Is it the same if you use cmd = ['arp', '-a'] RE: Hide CMD call window - snippsat - Apr-15-2024 When i test your code no cmd window pop up. This correct and normal behavior,what are you using to schedule code every hour? If you run code from command line python arp_code.py ,dos still cmd window pop up?Can also change to this,same no cmd window shall pop up. import subprocess with open('arp.txt', 'w') as fp: output = subprocess.run(['arp', '-a'], encoding='utf-8', capture_output=True) #print(output.stdout.strip()) fp.write(output.stdout.strip()) RE: Hide CMD call window - DeaD_EyE - Apr-15-2024 windows ... import subprocess def arp(): """ Run arp -a and return the stripped output. Window creation is prevented. """ flags = subprocess.CREATE_NO_WINDOW return subprocess.run( ["arp", "-a"], capture_output=True, encoding="utf8", creationflags=flags, ).stdout.strip() RE: Hide CMD call window - tester_V - Apr-16-2024 Yes, DOS window was popping up very hour, I understand it was running " arp -a". Outstanding! It is what I wanted/needed. You guys (girls?) are great! Thank you! RE: Hide CMD call window - tester_V - Apr-16-2024 I was happy too early it still pops up. I'm not sure how to incorporate "Dead_YEY" snippet correctly to the code I have. I tried to modify it but it does not work: import subprocess from subprocess import CREATE_NO_WINDOW flags = subprocess.CREATE_NO_WINDOW with open('C:\\somedir\\ARP_A.txt','w') as e : output = subprocess.run(['arp', '-a'], encoding='utf-8', capture_output=True) creationflags=flags output.write(output.stdout.strip()) RE: Hide CMD call window - deanhystad - Apr-16-2024 creation_flags=flags doesn't do anything in your code because you put it in the wrong place.. This runs fine for me. No window popping up on windows 10. import subprocess print( subprocess.run( ["arp", "-a"], encoding="utf-8", capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW, # Notice this is a function argument, not variable assignment ) ) RE: Hide CMD call window - tester_V - Apr-16-2024 it works, no pop ups! deanhystad, you are DA MAN! Thank you! RE: Hide CMD call window - deanhystad - Apr-16-2024 Dead EYE is da man. You need to develop a more critical eye so you can spot your own coding errors. |