简体   繁体   中英

Python execution from php using exec()

I am trying to call a python script from php which have proper execution permission but the script contains some of the commands for which only the root has the permission. So how can i make sure that those commands runs properly from the webservice???

I followed this link: Running a Python script from PHP but could not understand how to do it. If someone could explain, it will be a great help.

I will give you the usual warning regarding having PHP anywhere near root. I only do this because you mention this is a webservice (public facing?).

I recently published a project that allows PHP to obtain and interact with a real Bash shell (as user: apache/www-data or root if needed). Get it here: https://github.com/merlinthemagic/MTS

After downloading you would simply use the following code:

//Setting the second argument in getShell():
//true will return a shell with root
//false will return a shell with the php execution user
$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1  = $shell->exeCmd('python /full/path/to/python_script.py');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM