Run Python program from PHP

WBOY
Release: 2023-09-05 20:26:02
forward
1627 people have browsed it

Run Python program from PHP

In PHP, you can use the ‘shell_exec’ function. It can be executed via the shell and returns the result as a string. If NULL is passed from the command line or there is no output, an error is returned.

The following is a code example with the same function:

<?php
   $command_exec = escapeshellcmd(&#39;path-to-.py-file&#39;);
   $str_output = shell_exec($command_exec);
   echo $str_output;
?>
Copy after login

Need to give the correct permissions in order to successfully execute the Python script.

Note − When working on Unix type platforms, the PHP code is executed as the web user. Therefore, web users should be given the necessary permissions on directories and subdirectories.

The above is the detailed content of Run Python program from PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!