-1

Can I run a script or a .exe file every time the command prompt is executed from various methods? like maybe through Run or the toolbar in Explorer or anywhere. I want to run a script and show something in the command prompt as an output.

avocadoLambda
  • 1,332
  • 7
  • 16
  • 33
  • 1
    Clarify "everytime commandprompt is executed". Do you mean every time the cmd console is launched? – Peter Constable Jun 27 '20 at 16:49
  • yes everytime you launch the cmd. – Bishant Adhikari Jun 27 '20 at 16:53
  • 1
    Please do __not__ use registry value `AutoRun` of registry key `HKCU\Software\Microsoft\Command Processor`. That would be really a very bad idea. The command line specified here is executed whenever `cmd.exe` is executed independent on which process started `cmd.exe`. `cmd.exe` starts itself for example on usage of `for /F "eol=| delims=" %%I in ('dir /A-D /B 2^>nul') do echo File "%%I"` in a batch file. Thousands of programs and scripts run in background `cmd.exe` indirectly (most often without programmer knowing that). So usage of `AutoRun` would be a very bad idea in most cases. – Mofi Jun 27 '20 at 18:29

1 Answers1

0

If you are asking to run Python script/code on cmd then run this code: import py_compile py_compile.compile(filename.py,output_name.pyc)

This will create a .pyc file which you can then run in cmd using command: python output_name.pyc

note: filename and output_name are both strings that should include fileextensions and you can write any name here.