Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hide CMD call window
#1
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 Angry .
How I can suppress the pop up window?
code:
1
2
3
4
5
6
7
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.
Reply
#2
Is it the same if you use
1
cmd = ['arp', '-a']
tester_V likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
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.
1
2
3
4
5
6
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())
Reply
#4
windows ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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()
tester_V likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
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!
Reply
#6
I was happy too early Cry
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:
1
2
3
4
5
6
7
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())
Reply
#7
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.
1
2
3
4
5
6
7
8
9
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
    )
)
tester_V likes this post
Reply
#8
it works, no pop ups! Big Grin
deanhystad, you are DA MAN! Wink

Thank you!
Reply
#9
Dead EYE is da man. You need to develop a more critical eye so you can spot your own coding errors.
tester_V likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 5,499 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,980 Jun-13-2022, 08:59 AM
Last Post: Shena76
  Hide symbol or characters in regular expression Gateux 0 2,780 Mar-21-2020, 10:25 AM
Last Post: Gateux
  I can't hide borders and _ [] X in window. storzo 4 3,547 Aug-04-2019, 09:55 AM
Last Post: storzo
  How to hide code Jupyter Notebook Larz60+ 0 5,866 May-07-2018, 02:45 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020