Last Updated : 12 Jul, 2025
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 executes the command (a string) in a subshell. This method is implemented by calling the Standard C function system() and has the same limitations. If the command generates any output, it is sent to the interpreter's 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.
Interact with Operating System using Python ExamplesSyntax: 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.
There are various uses of os.system in the Python operating system or OS command. here we are discussing some general uses of os.system in the Python operating system or OS command those are following.
Get the Current DateIn this example, code imports the `os` module or uses the OS command and uses `os.system('date')` to execute the 'date' command in a Windows operating system.
Python
# importing os module
import os
# Command to execute
# Using Windows OS command
cmd = 'date'
# Using os.system() method
os.system(cmd)
Output:
OS system Method to Run NotepadIn this example code imports the `os` module or use the OS command and uses `os.system('notepad')` to execute the 'notepad' command on a Windows operating system, opening the Notepad application.
Python
# importing os module
import os
# Command to execute
# Using Windows OS command
cmd = 'notepad'
# Using os.system() method
os.system(cmd)
Output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4