admin管理员组

文章数量:1134247

I am trying to run A python Script as mentioned in the following link..

Running a python script within wordpress

But I am still getting the message "permission denied".

I am trying to run A python Script as mentioned in the following link..

Running a python script within wordpress

But I am still getting the message "permission denied".

Share Improve this question asked Nov 25, 2020 at 5:32 shekhar singhalshekhar singhal 111 bronze badge 3
  • Does your script have the 'x' executable permission set for the user your web server is running as? (However it might be better to call the python interpreter explicitly, rather than just running the .py script directly, else you've really written a 'run arbitrary command' shortcode not a python shortcode.) – Rup Commented Nov 25, 2020 at 9:16
  • yes. it is having permission.. – shekhar singhal Commented Nov 30, 2020 at 8:22
  • OK, then you're going to have to work out where the 'permission denied' is coming from then. I don't think you've given us enough information to help you. – Rup Commented Nov 30, 2020 at 8:24
Add a comment  | 

1 Answer 1

Reset to default 1

This issue of permission denied is resolved.. Permission was already given but I have added 'env python' in the popen function.. Now the code is running as expected..

add_shortcode( 'run_test_py', 'test_py' );

function test_py( $attributes )
{
    $data = shortcode_atts(
        [
            'file' => 'test.py'
        ],
        $attributes
    );

    $handle =  popen('env python '. __DIR__ . '/' . $data['file'] . ' 2>&1', 'r' );
    $read = '';

    while ( ! feof( $handle ) )
    {
        $read .= fread( $handle, 2096 );
    }

    pclose( $handle );

    return $read;
}

本文标签: pluginsRun Python Script on WordPress Website