How to open command prompt using python and then executing commands using python

 

English

Introduction

In this page you will learn to open and run commands in command prompt (cmd) using python.

Command prompt (cmd)
You can easily get a well defined definition of command prompt on any website.But ,to understand it easily ;for instance we can say that it is a tool through which,We can perform various tasks by simply typing appropriate commands in it.

How to Access Command Prompt in Windows

In windows we can access command prompt in various ways. The easiest way is ; USING SHORTCUTS. Shortcut for this purpose is  :-"Windows key"+"R" and then click "OKAY". 

Steps To access command prompt using python:- 
  • Importing Module:-
    • import os
    • import subprocess
  • Typing commands
    • cmd = subprocess.Popen('cmd.exe /C YOUR COMMAND')
To use multiple command use "&&" between  the commands

For ex. Your Source Code will be as follows:-
import os
import subprocess
cmd = subprocess.Popen('cmd.exe /C cd /d C:\Program Files (x86)\Google\Chrome\Application && chrome.exe --remote-debugging-port=8989 --user-data-dir="E:\Atharva\chromeprofile')

Click for full resolution image.



  

"Hope it helped"
Have anything in mind? Let me 
know in the comment section👇

Next Post Previous Post
No Comment
Add Comment
comment url