Python System Command
To execute a program in Python, we need to execute some shell commands to run our program on the computer. Python will provide some shell commands in our background to run the program. Let us consider executing the LIME module in Python; for this, we need to execute some command lines; these commands will interact with the operating system and run the program.
Generally, a python programming language will provide us with the OS module, which will provide us with the functions that will interact with the operating system in our computer and help us run the program. The OS module will fall under Python's standard utility module category. These shell commands will help automate the computer tasks to run the program in a structured and scalable manner.
Python os.system( ) Method
The python os.system( ) function or method helps execute the command in the subshell. This function will be implemented by calling the Standard C function system ( ) with the same limitations. After running this function, if the command generates any output, it will be sent to the interpreter, and we can visualize the output. This Os.system( ) function runs in the following way, when we call this function, it will directly open the corresponding shell in the operating system, and then the command is executed on the respective shell.
Syntax:
os.system(command)
Parameters:
We will give the command as an input, a string data type; this command will help the operating system execute.
Return:
In UNIX, the return value will be the program's exit status, and on Windows, the return value will be exit values obtained from the system shells after running the command.
Example:
Let us consider an example of executing a command in the os.system( ) function, which will return the current day.
Code:
#importing the libraries
importos
# Adding the command value
#With the help of the windows os command
command = ‘day’
#Calling the os.system( ) method
os.system(command)
Output:
The current day is: Saturday
Example:
Let us consider another example of running the command to open the notepad in the computer with the help of the os.system( ) function.
Code:
#importing the module
importos
#Getting the command value which must be executed
# Running the Windows OS command
command = ‘Notepad’
# Calling the os.system( ) function
os.system(command)
Output:

Example:
Let us consider an example of executing a command in the os.system( ) function, which will return the current date.
Code:
#importing the libraries
importos
# Adding the command value
#With the help of the windows os command
command = ‘date’
#Calling the os.system( ) method
os.system(command)
Output:
The current date is: Saturday, 1-10-2022
Python subprocess.call() Module:
The python subprocess.call ( ) function or module is the same as theos.system( ) function, but after running this function, the value obtained at the output is stored in some variable.
The subprocess module is the updated version of the os.system( ) function. Nowadays, the subprocess.call( ) function is used for all the shell process rather than the os.system( ) function.
Example:
Let us consider an example of executing a command in the os.system( ) function, which will return the current day.
Code:
#importing the libraries
importos
# Adding the command value
#With the help of the windows os command
command = ‘day’
#Calling the subprocess.call( ) method
return_output = subprocess.output(command)
# Calling the decode( ) function to convert the byte string into the string
print( 'The Current day is:', return_output.decode(“utf))
Output:
The Current day is: Saturday
Example:
Let us consider another example of running the command to open the notepad in the computer with the help of the os.system( ) function.
Code:
#importing the module
importos
#Getting the command value which must be executed
# Running the Windows OS command
command = ‘Notepad’
# Calling the subprocess.call( ) function
output= subprocess.return(command)
#Displaying the output
print(output)
Output:

Example:
Let us consider an example of executing a command in the os.system( ) function, which will return the current date.
Code:
#importing the libraries
importos
# Adding the command value
#With the help of the windows os command
command = ‘date’
#Calling the Subprocess.call( ) method
return_value= subprocess.output(command)
#Converting the byte string into the string using the decode function
print('The Current date is:’, return_output.decode(“utf)
Output:
The current date is: Saturday, 1-10-2022