简体   繁体   中英

html not printing out output text

So i have two codes, one of them is just a simple code that i used to test out some php functions. I'm trying to print out the JSON string into my html, one of the codes is working but the other isn't.

So let's say that we have two sets of codes : first.php & first.py , second.php & second.py

first.php looks like this:

<?php
exec("C:/Users/hln/Anaconda3/envs/tensorflow1/python.exe C:/tensorflow1/models/research/object_detection/first.py", $output);
$someOutput = json_decode($output[0], true);
echo "<h3>" . $someOutput['rightCoordinate'] ."</h3>";
echo "<h3>" . $someOutput['leftCoordinate'] ."</h3>";?>

first.py looks like:

import json
a = 1 + 3
b = 5 + 5

x = {
  "leftCoordinate": a,
  "rightCoordinate": b
}

y = json.dumps(x)
print(y)
print()

second.php looks like this:

<?php
exec("C:/Users/hln/Anaconda3/envs/tensorflow1/python.exe C:/tensorflow1/models/research/object_detection/second.py C:/xampp/htdocs/w3layout/finalproject/uploads/10.PNG 10.PNG 2>&1",$output);
$someOutput = json_decode($output[0], true);
echo "<h3>" . $someOutput['theWidth'] ."</h3>"; ?>

second.py looks like:

outputvalues = {
    "leftCoordinate" : x_min(each of these are already defined),
    "rightCoordinate" : x_max,
    "lowerCoordinate" : y_min,
    "upperCoordinate" : y_max,
    "numInjuries" : count,
    "theWidth" : im_width,
    "theHeight" : im_height
}

y = json.dumps(outputvalues)
print(y)

when i run them in command prompt, the first one will result:

{"leftCoordinate": 4, "rightCoordinate": 10}

and when i put it in my html it will print out 4 and 10

the second one have this result in command prompt:

{"leftCoordinate": 34.47790487855673, "rightCoordinate": 251.67991018295288, "lowerCoordinate": 208.6769086420536, "upperCoordinate": 388.4499931335449, "numInjuries": 1, "theWidth": 327, "theHeight": 503}

but it won't print out any result in html

is there anything that i should change?

This might not be a helpful answer because there does not seem to be anything wrong with your code.

I placed the following at the top of second.py:

import json

x_min = 34.47790487855673
x_max = 251.67991018295288
y_min = 208.6769086420536
y_max = 388.4499931335449
count = 1
im_width = 327
im_height = 503

and removed the absolute paths in second.php:

exec("second.py 10.PNG 10.PNG 2>&1",$output);

Now php second.php shows me <h3>327</h3> .

This is on Windows 10 with PHP 7.3.1 and Python 3.7.4.

Edit: Tried it on Ubuntu 19.04/PHP 7.2.19/Python 2.7.16 and got the same result.

Based on your comments the problem is the fact that the Python script generates a warning which is then passed to the PHP script.

One way to ignore the warnings is to add the -W option with a value ignore . The line in the PHP script would then look something like this:

exec("python -W ignore second.py", $output);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM