-1

Im trying to call to a python file from php using shell_exec command. But shell_exec doesen't give any out put.

I run the python script on terminal and it gave me the correct output

  python3 var/www/html/thilina/assets/documents/threadsearch.py keyword,equipment_types/2

This how i call the python script in my controller

  $key = $this->input->post('search');//from ajax       
  $fnum = $this->input->post('sub');//from ajax      
  $sym = $key.",".$fnum;//search key + 2   
  $chk = FCPATH."/assets/documents/threadsearch.py";
  $chk = str_replace('\\', '/', $chk);
  $output = shell_exec("python3 $chk $sym");//get the output from python script
  • Give permission of execute to `www-data`. Refer [This answer](https://unix.stackexchange.com/questions/115054/php-shell-exec-permission-on-linux-ubuntu/127529#127529) – PrakashG Sep 12 '19 at 11:00
  • Possible duplicate of [php shell\_exec doesn't work in browser but works in terminal](https://stackoverflow.com/questions/13680504/php-shell-exec-doesnt-work-in-browser-but-works-in-terminal) – stefo91 Sep 12 '19 at 13:04

1 Answers1

0
  1. Try to catch error stream by appending 2>&1 to the command: $output = shell_exec("python3 $chk $sym 2>&1"); See PHP - How to get Shell errors echoed out to screen

  2. You potentially have an OS command injection vulnerability (you concatenate user input with a shell command). See https://portswigger.net/web-security/os-command-injection

Andrew
  • 693
  • 3
  • 5