In Python, you can execute a program or call a system command using the subprocess
module. Here’s a simple example:
Replace 'command'
with the program name and its arguments. The capture_output=True
option captures the command’s output, and text=True
ensures it’s returned as a string.
For simpler use cases, you can use os.system(command)
, but subprocess
is more powerful and secure. Always validate inputs to avoid security risks like command injection.