Reputation: 105
Is it possible to use os.popen()
to achieve a result similar to os.system
? I know that os.popen()
is more secure, but I want to know how to be able to actually run the commands through this function. When using os.system()
, things can get very insecure and I want to be able to have a secure way of accessing terminal commands.
Upvotes: 1
Views: 1446
Reputation: 9575
Anything that uses the shell to execute commands is insecure for obvious reasons (you don't want someone running rm -rf /
in your shell :). Both os.system
and os.popen
use the shell.
For security, use the subprocess
module with shell = False
Either way, both of those functions have been deprecated since Python 2.6
Upvotes: 3