Ross, i think i don't want to use external script, like
my_script.py ...

On Jan 2, 12:20 am, Ross Peoples <ross.peop...@gmail.com> wrote:
> I use subprocess.Popen a lot to run shell commands from Python. There is no
> need for a specific web2py feature.
>
> This is the method I use whenever I need to call something:
>
>     import subprocess
>     def run_command(self, *args):
>         """
>         Returns the output of a command as a tuple (output, error).
>         """
>         p = subprocess.Popen(args, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE)
>         return p.communicate()
>
> It's very simple to use:
>
> output, error = run_command('python', 'my_script.py', 'arg1', 'arg2', ...)
>
> This runs the command, waits for it to exit, and then you have a string
> "output" for the output from the command, and a string "error" for any
> error output from the command.

Reply via email to