@Joy_Lewis ,yes you can call an external command within your python script.Following are the different ways of calling an external command in python-
1. Using the subprocess module
For new Python versions:
import subprocess
subprocess.run(["ls", "-l"])
For old Python versions:
import subprocess
subprocess.call(["ls", "-l"])
2. Os.system(“some_command with args”)
os.system("some_command < input_file | another_command > output_file")
3. Using popen class from the subprocess module
print subprocess.Popen(" Hello World", shell=True, stdout=subprocess.PIPE).stdout.read()
You may also use os.system() method but using subprocess is more advantageous.
According to the official Python document (https://docs.python.org/3/library/os.html#os.system), subprocess module is a much better alternative for os.system()because:
- Subprocess is more flexible as compared to the system.
- Subprocess module provides better facilities of spawning a new process and retrieving their results.
Hope this answer will help.