xxxxxxxxxx
// To run pytho script from CMD
// type python and the name of the file. Assuming hello.py
python hello.py
xxxxxxxxxx
CMD /K - execute a command then remain
import os
os.system('cmd /k "Your Command Prompt Command"')
xxxxxxxxxx
import os
os.system("ma Commande")
#Exemple:
os.system("cd Documents")
xxxxxxxxxx
import subprocess
import sys
# Some code here
pid = subprocess.Popen([sys.executable, "longtask.py"]) # Call subprocess
# Some more code here
xxxxxxxxxx
import subprocess
# for simple commands
subprocess.run(["ls", "-l"])
# for complex commands, with many args, use string + `shell=True`:
cmd_str = "ls -l /tmp | awk '{print $3,$9}' | grep root"
subprocess.run(cmd_str, shell=True)
xxxxxxxxxx
# press [windows] + [R] (on windows only)
# use the command : cd/the_way_of_your_program
# and now use this command :
py the_name_of_your_program.py
# don't forget to write the extension (py for python)
# at the end of your program name