php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74965 exec() does'nt work anymore since PHP 7.0 was updated to version 7.0.21.
Submitted: 2017-07-21 14:11 UTC Modified: 2017-07-25 13:01 UTC
From: jean-christophe dot ventre at wanadoo dot fr Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.21 OS: windows server 2012R2
Private report: No CVE-ID: None
 [2017-07-21 14:11 UTC] jean-christophe dot ventre at wanadoo dot fr
Description:
------------
//googleApiKey : using a python script this allow the final user to see his own reports //without the necessity to be login in

$cmd='.\assets\python\service-account.py C:\\Python27\\python.exe';
exec("$cmd", $output);
$this->data['googleApiKey']=$output[0];

This script doesn't work anymore since the php update from 7.0 to 7.0.21.


I do not have any error message, for example 


$cmd='.\assets\python\test.py C:\\Python27\\python.exe';

$mystring = exec("$cmd", $output, $return_var);
echo 'result : ' .$mystring.'</br>';
echo 'return_var :'.$return_var.'</br>';
var_dump($output);

will display

result : 
return_var :1
array(0) { }

where test.py :

# -*-coding:Latin-1 -*
import os 

def result():
 print("resultat")


if __name__ == "__main__":
    result()	






Test script:
---------------
$cmd='.\assets\python\test.py C:\\Python27\\python.exe';

$mystring = exec("$cmd", $output, $return_var);
echo 'result : ' .$mystring.'</br>';
echo 'return_var :'.$return_var.'</br>';
var_dump($output);


where test.py :

# -*-coding:Latin-1 -*
import os 

def result():
 print("resultat")


if __name__ == "__main__":
    result()	


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-21 15:04 UTC] kalle@php.net
-Status: Open +Status: Feedback
 [2017-07-21 15:04 UTC] kalle@php.net
Are you sure you didn't mean $cmd to be:

$cmd='C:\\Python27\\python.exe .\assets\python\test.py';

The only other way that calling '.\asserts\python\test.py' as an executable has to do with what executable is registered to execute .py files, which PHP does nothing about on Windows.
 [2017-07-22 08:41 UTC] ab@php.net
-Status: Feedback +Status: Not a bug
 [2017-07-22 08:41 UTC] ab@php.net
Obvious mistake in the command.

Thanks.
 [2017-07-24 08:14 UTC] jean-christophe dot ventre at wanadoo dot fr
Thanks for your help,but 

$cmd='.\assets\python\service-account.py C:\\Python27\\python.exe';
exec("$cmd", $output);

is working perfectly well on three differents servers and php configurations  since 2 years now.

however, you are right,
$cmd='C:\\Python27\\python.exe .\assets\python\service-account.py ';
exec("$cmd", $output); 
works as well.

The two syntaxes work, not so sure one of them  must be prohibited ?

Whatever, the code was working perfectly well until the  php 7 update from 7.0.0 to 7.0.21 and i am still looking why
 [2017-07-24 08:36 UTC] kalle@php.net
Hi Jean, the reason why it doesn't work has nothing to do with PHP, but the operating system that PHP is installed off. In this case Windows, you will need to register extension as an executable before calling that extension directly will work.

For example to make the script work for .php files, you would need to do:
1) Modify PATH to include a location to where PHP is installed
2) Modify PATHEXT to include .php
3) Run 'assoc .php=phpfile'
4) Run 'ftype phpfile="C:\path\to\php" -f "%1" -- %~2'

The same concept can be applied to Python, and that was probably the case on your host system, but it probably doesn't work because PHP7 was installed in a different place.

You can see more about this in the manual:
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline

Thank you for using PHP!
 [2017-07-24 13:25 UTC] jean-christophe dot ventre at wanadoo dot fr
@kalle@php.net thanks for your reply.
I have just reading it. 
Ten hours now, that's going to drive me crazy.

I will definitely need your help, i swear on God that the code was perfectly working until last week.
But now i'm starting to think that was by pure luck..

You are right this is not a php bug .
I was incriminate php because the problem happening in the same time than an automatic update of php by plesk..

I will try to run a php script..

I'll keep you informed
 [2017-07-24 14:16 UTC] jean-christophe dot ventre at wanadoo dot fr
O shit, i changed the environnements variables in windows adding entries for php and now nothing works anymore.
Ten php websites shutdown, it's a nightmare !
 [2017-07-25 13:01 UTC] jean-christophe dot ventre at wanadoo dot fr
Finally works again after setting new environnement variables  and removing and reinstalling python in another path
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC