You need to use the subprocess module in order to deal with command lines inside a python script.
If the only thing you need is to get the output of your command, then use subprocess.check_output(cmd).
cmd is a sequence (python list) of program arguments. So, if your command only contains one word (such as date), it will work using cmd="date". But if you have a longer command (for example cmd="grep 'pattern' input_file.txt"), then it will not work, as you need to split the different arguments of your command line. For this, use the shlex module: shlex.split(cmd) will return the appropriate sequence to subprocess.
So, the code for your cmd_simulator would be something like:
import subprocess
import shlex
def cmd_simulator(cmd):
return subprocess.check_output(shlex.split(cmd))
And of course, you can add to this function some try/except to check that the command is working, etc.
If you don't only need the stdout of your command but also stderr for example, then you should use subprocess.Popen(cmd).
subprocess.check_outputmay be be useful to you.cmd_simulator=lambda cmd:os.popen(cmd).read();print cmd_simulator("date")