So I am trying to make some code that writes a certain command in cmd and im not sure how to make a python code that opens cmd and writes in that command, any help?
I googled and tried some stuff but no results
CodePudding user response:
I didn't understand if you want to just write on cmd or execute it. If you want to execute you can use:
import os
os.system('cmd /k "Your Command Prompt Command"')
/k will keep cmd open if you use /c it will execute and terminate
source: https://datatofish.com/command-prompt-python/
CodePudding user response:
You can locate your cursor position in a working directory. Then write python3 followed by your name_of_the_script_code.py