

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Run a Python program from PHP
In PHP, the ‘shell_exec’ function can be used. It can be executed via the shell and the result can be returned as a string. It returns an error if NULL is passed from the command line or returns no output at all.
Below is a code demonstration of the same −
<?php $command_exec = escapeshellcmd('path-to-.py-file'); $str_output = shell_exec($command_exec); echo $str_output; ?>
The right privileges need to be given so that the python script is successfully executed.
Note − While working on a Unix type of platform, PHP code is executed as a web user. Hence, the web user should be given the necessary rights to the directories and sub-directories.
- Related Questions & Answers
- How to Run a Python Program
- How to run Python Program?
- How to run Python functions from command line?
- How to run a java program
- Run Python script from Node.js using child process spawn() method?
- How to run Perl Program?
- Run Length Encoding in Python
- How to run Java package program
- How to run a PowerShell script from the command prompt?
- How to run TestNG from command line?
- Program to decode a run-length form of string into normal form in Python
- Program to implement run length string decoding iterator class in Python
- Why does Python code run faster in a function?
- Program to encode a string in normal form to its run-length form in Python
- How to run JavaTuples program in Eclipse?
Advertisements