On Jul 3, 2012, at 10:21 PM, 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?
> 

By default, subprocess.call executes your command directly. In particular, 
there's no shell involved, and no splitting of an argument string into its 
individual arguments, so  you have to do that yourself. So if you have more 
than one argument in args, you'll need to split them apart:

> subprocess.call(['python','script.py', arg1, arg2, arg3])
or

> subprocess.call(['python','script.py', *list_of_args])
or

> subprocess.call(['python','script.py', args], shell=True)
or teach script.py to parse a single argument into pieces. 

If I'm guessing wrong about what you have in args, try putting some debug logic 
into script.py and report what it's actually seeing.

Reply via email to