0

I'm trying to execute a Python script stored in the 'private' folder of a web2py application. My code, in the index() function of the default.py controller

import os

def index():
    fp = os.path.join(request.folder, 'private', 'runscrape.py')
    did_scrape = True if os.system('python ' + fp) else False

This code should execute every time the index is loaded. while did_scrape is returning True, the script is certainly not executing. did_scrape returns true whether I use the fp variable above or hardcode the path directly. Am I missing something basic about executing scripts in web2py?

murty
  • 145
  • 1
  • 6

1 Answers1

0

value did_scrape is True means if condition is satisfied.

The Return value of os.system() is the exit status of the process, i.e. os.system() returns 0 if python script executed without errors.

So in your case os.system() is returning non-zero value(exit status).

I think your python script has errors or some issue with python script path.

Read os.system()

Gaurav Vichare
  • 1,143
  • 2
  • 11
  • 26