How to run a python script with cmd.exe and make it invisible

How do I run an invisible cmd.exe command?

Example:

C:\Python27\tool.py

and make it visible after a while?

I tried some methods that I found on Google but I'm not very satisfied. I do not have administrative rights on this PC either if that makes a difference.


Solution 1:

How to run invisible a cmd.exe command,example:

Below is one example you may find works as you describe:

  1. You will have the batch file with the below logic named tool.bat

    • @ECHO OFF
      python "C:\Python27\tool.py"
      EXIT /B
      

  1. You will have a VBS file with the below logic named tool.vbs

Ensure the path below in the C:\tool.bat part is pointed to the correct path to the batch file

  • Set WinScriptHost = CreateObject("WScript.Shell")
    WinScriptHost.Run Chr(34) & "C:\tool.bat" & Chr(34), 0
    Set WinScriptHost = Nothing
    

  1. You will then execute the tool.vbs file and your process should run hidden.

make it visible after a while?

To run python script with cmd and show output

CMD /K START "" "C:\Python27\tool.py‌​"