我对循环和 glob 和 os 模块有问题。在 python Shell 中打印打印但是当我在 php 中嵌入我的 python 脚本时它不起作用。
下面通过 PHP 的 python 只打印“first”和“second”,但不打印“current file is:...”。
也许我找到了另一种阅读目录的方法?glob 和 os 模块与 PHP 不兼容?
Python:
print("first")
path = 'cat/tryfile'
for infile in glob.glob( os.path.join(path, '*.jpg') ):
print("current file is: " + infile )
print("second")
PHP:
$param1 = "first";
$param2 = "second";
$param3 = "third";
$command = "C:\\python27\\python C:\\Python27\\execprova.py";
#FIRST PYTHON embedding with popen
$command .= " $param1 $param2 $param3 2>&1";
$temp = exec($command, $return);
echo "INIZIO PID";
$pid = popen( $command,"r");
echo "<body><pre>";
while( !feof( $pid ) )
{
echo fread($pid, 256);
flush();
ob_flush();
usleep(100000);
}
pclose($pid);
#SECOND PYTHON embedding with exec
echo (" {PHP inizio command output return ed exec /PHP} ");
$command = "C:\\python27\\python C:\\Python27\\bp1imgsenzaprint.py";
$output = null;
$temp = exec($command);
function success()
{
$mystring = exec('C:\\python27\\python C:\\Python27\\bp1imgsenzaprint.py', $output);
var_dump($output);
var_dump($mystring);
print_r($output);
}
print("SUCCESS");
success();