Open In App
Related Articles

Python | os.system() method

Improve Article
Improve
Save Article
Save
Like Article
Like

The OS module in python provides functions for interacting with the operating system. OS, comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.system() method execute the command (a string) in a subshell. This method is implemented by calling the Standard C function system(), and has the same limitations. If command generates any output, it is sent to the interpreter standard output stream. Whenever this method is used then the respective shell of the Operating system is opened and the command is executed on it.

Syntax: os.system(command)

Parameter:
command: It is of string type that tells which command to execute.

Return Value: On Unix, the return value is the exit status of the process and on Windows, the return value is the value returned by the system shell after running command.

Example #1 :
Using os.system() method to get current date of computer




# Python program to explain os.system() method 
      
# importing os module 
import os 
  
# Command to execute
# Using Windows OS command
cmd = 'date'
  
# Using os.system() method
os.system(cmd)


Output:

Example #2 :
Using os.system() method to run Notepad.




# Python program to explain os.system() method 
      
# importing os module 
import os 
  
# Command to execute
# Using Windows OS command
cmd = 'notepad'
  
# Using os.system() method
os.system(cmd)


Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 20 Jun, 2019
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials