output of exec($pythonscript $array) 【error】

The print sends the output to the process’ STDOUT stream. That will probably end up being the STDOUT of the PHP process which may be in an Apache log. If you want send that stream and send it to the browser, you will need to capture it.

PHP sends ‘echo’ output to the HTTP stream. Python sends it to STDOUT

When you run PHP from the command line, you’re running a single process, and echo does go to STDOUT. But running on a server, the output has to go to the appropriate HTTP request/response. I can’t be bothered to look into it, but I imagine that the PHP process is probably threaded, serving several concurrent requests per process.

string exec ( string $command [, array &$output [, int &$return_var ]] )

exec() executes the given command .

2>&1 needs to be added in the command to get the complete output.

The exec function just return the last line from the result of the command.

$command = "python ./fmiq_python/queryfile.py ../portrait/N06242_10.jpg 2>&1"; exec($command,$out);
echo current($out); //Error:Cannot open image database

python 改变当前工作路径:

#!/usr/bin/php

<?php
chdir('/home/');
echo getcwd();
$content = `ls -al`;
var_dump($content);
echo getcwd()."\n"; //取得当前工作目录

使用PHP获取文件名和扩展名

  • 文件名:

// 第一种

$filelen=strpos($filename,’.’) //获取文件名长度
$filename_name=substr($filename, 0, $filelen); //截取文件名
// 第二种
$file_name=substr(basename($file_path),0,(strlen(basename($file_path))-strlen($file_type)-1))

  • 扩展名:

// 第一种
$extendname = array_pop(explode ( ".",$filename));  
// 第二种
$extendname = end(explode(".", $filename));
// 第三种
$file_part  = pathinfo($filename); 
$extendname = $file_part["extension"];

$file=explode(“.”,basename($file_path))//数组元素就是文件名通过.分割的各个字符串,如a.exe获得了arrey{a,exe},

    • end($file)获取到数组最后一个元素,即为文件的后缀名,文件类型。
    • $file[0],得到文件名?//对a.b.c.exe这类文件名,单纯用数组就很难得到理想的结果

php获取路径中文件名部分:

<?php
$path = "/home/httpd/html/index.php";
$file = basename($path);        // $file is set to "index.php"
$file = basename($path,".php"); // $file is set to "index"
?>
$filepath = "/html/contents.txt";
//使用basename()函数获取路径中的文件名部分
echo $filepath."中的文件名是:".basename($filepath);

$command = “python ./fmiq_python/queryfile.py $query_upload_path 2>&1″;

exec($command,$out);

$downloadFileName = basename(end($out));
streamFile($downloadFile_path.$downloadFileName, $downloadFileName,”application/octet-stream”);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: