やりたいこと
exec関数を使いpythonを実行し、実行結果を取得したい。
実行環境
os:mac
ブラウザ:breve
PHPエンジン:MAMP
やったこと
php
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title>Document</title> 8</head> 9<body> 10 <?php 11 12 $command='python /フルパス.py'; 13 exec($command, $output); 14 15 echo $output; 16 17 ?> 18</body> 19</html>
python
1a=1 2b=3 3c=a+b 4 5print(c);
私がやりたいことはphpでpythonの実行結果(c)を取得し、
phpでechoしたいのですが「Warning: Undefined array key 0」が出て失敗してしまいます。
コマンドラインでphpを実行すると取得できているので、パスとかが違うんですかね???
(コマンドラインでの実行結果: 4 //本当はhtmlの雛形も表示されるのですが、ややこしくなるので省略しました。)
ご存じの方がいらっしゃればご教授いただけると幸いです。
回答1件
あなたの回答
tips
プレビュー