Python script call from php does not execute as expected

I created a python script to get a directory tree. Now I am trying to call this script from php using system ().

My Python script:

import os
from sys import argv

script, start = argv

def list_files(startpath):

    directory = []

    for root, dirs, files in os.walk(startpath, topdown=True):

        for named in dirs:
            directory.append(os.path.join(root, named))

        for namef in files:
            directory.append(os.path.join(root, namef))

        return directory

dir = list_files(start)

      

My PHP command:

$var = system('C:\\Python27\\python.exe generate -tree.py F:\\IET', $retval);
echo $var;
echo $retval;

      

The result I get in the browser is the number "2" and when I did it the day before exiting as the number "1".

I'm new to PHP so couldn't figure out what I was doing wrong here. Any guidance would be appreciated!

+3
python php web directory-structure


source to share


No one has answered this question yet

Check out similar questions:

4473
Calling an external command in Python
2335
Removing an element from an array in PHP
1675
Why is reading lines from stdin much slower in C ++ than Python?
1470
How do I remove a key from a Python dictionary?
1315
How do I remove an item from a list by index?
1183
How can you profile a Python script?
1139
Extracting extension from filename in Python
1069
How can I check which version of Python my script is running?
792
Returning JSON from PHP script
638
Shutdown Python script



All Articles
Loading...
X
Show
Funny
Dev
Pics