Python Forum

Full Version: Minimizing the CMD window during code execution
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Attaching the snippet of my code.

Objective: I am trying to ping a website for certain interval of time (User defined). If the URL works, it will open the webpage in the default browser. If not it will keep pinging until the user defined time interval expires.

Issue: Code works perfectly but at instruction
Quote:response = os.system("ping " + url)
, it pops up the cmd window on screen and I need to minimize it every time. It is irritating to do it manually all the time. Is there any way I can resize the terminal window or make it minimize all the time until the code expires?

A little manual study lands me to this os.get_terminal_size() but nothing much.


import os, time, webbrowser

#Enter URL that need to check. Add input()
url = "167.6.2.200"
input_time = float(input("How long ping should work: "))

current_time = time.time()   #note current time
actual_time = 0
isHostOn=0

#r = (os.get_terminal_size())
response =0 

#Execute the loop till the time expires entered by User
while((input_time + current_time) > actual_time): 
    response = os.system("ping " + url)
    if response ==0:
        webbrowser.open_new_tab("https://167.6.2.200:446/")
        break;
    else:
		#add Exception if any
        #print("no")
        pass # do nothing

    actual_time = time.time()
    #time.sleep(5)
I have got to know about the subprocess and its return value.

Probably this StackoverFlow link will help: