Windows hides the Python runtime terminal

Source: Internet
Author: User

1. Use the start pythonw xxx.py to execute Python on the machine but hide the terminal, usually log to check for problems

2. Use ping to implement sleep operations and avoid interaction problems caused by the use of pause

app.py

Import osimport Timeimport datetimepid = os.getpid () fp = file ("App.pid", "WT") fp.write ("%d"% pid) Fp.close () while True: Time.sleep (1) FP = file ("App.log", "at") Fp.write ("%s\n"% Datetime.datetime.now ()) Fp.close ()

Start.bat

@echo Offif exist App.pid (echo "[%date%%time%] Running ..." Ping-n 3 localhost >nulexit) Else (echo "[%date%%time%] Starting ..." Start pythonw app.pyping-n 3 localhost >nulstatus.batping-n 3 localhost >nul)

Stop.bat

@echo Offif exist App.pid (echo "[%date%%time%] stopping ..." python-c "Import os;  Os.system (' taskkill/f/pid%%s ' percent open (' app.pid '). read ()); " Del App.pid) Else (echo "[%date%%time%] Stopped:" Ping-n 3 localhost >nul)

Status.bat

@echo Offif exist App.pid (echo "[%date%%time%] runningg ...") Else (echo "[%date%%time%] Stopped ...") Ping-n 3 localhost >nul

Restart.bat

@echo Offif exist App.pid (echo "[%date%%time%] stopping ..." python-c "Import os;  Os.system (' taskkill/f/pid%%s ' percent open (' app.pid '). read ()); " Del App.pid) Else (echo "[%date%%time%] Stopped:" Ping-n 3 localhost >nul) if exist App.pid (echo "[%date%%time%] Running ..." Ping-n 3 localhost >nulexit) Else (echo "[%date%%time%] Starting ..." Start pythonw app.pyping-n 3 localhost >nulstatus.batping-n 3 localhost >nul)


Windows hides the Python runtime terminal

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.