import shlex
task="%s %s -S myapp-M -N -R %s" \
%(sys.executable,
os.path.join(os.getcwd(),"web2py.py"),
os.path.join(request.folder, "modules", "mymodule.py"))
task = shlex.split(task.replace('\\','/')) # note shlex does not
recognise windows path character.
p=subprocess.Popen(task)
On Wednesday, 4 July 2012 06:21:27 UTC+1, suraj d wrote:
>
> I am trying to run a python script from web2py's controller function using
> subprocess.call method. But the script does not execute from there, but
> when I am running the same method from inside python shell, it runs without
> any problems.
>
> The command I wrote in web2py controller's function is:
>
> subprocess.call(['python','script.py', args])
>
> where args is a string containing command line arguments I want to pass to
> the script The command I wrote in python shell is:
>
> >>>subprocess.call(['python','script.py','args'])
>
> here I am directly passing the arguments.
>
> script.py creates multiple files in directory, but it doesn't do so with
> web2py.
>
> I have used subprocess multiple times within the web2py controller
> function without any problem and I have also tried changing the permission
> of script.py to 777, but it was not of any help either.
>
> Can anyone tell me where my mistake is?
>