问题描述:

<?php

$dd="/root/report/lastDate-28-11-2013.csv";

$c_row=exec("awk 'BEGIN { FS = \",\" } ; { print $1 }'" .$dd);

//echo $c_row;

print_r($c_row);

?>

When i run this code it simply hangs and does not print any output.

网友答案:

Have a look at the manual, you're missing an output and/or return_var parameter.

To get the output of the executed command, be sure to set and use the output parameter.

Syntax:

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

output

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().

return_var

If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.

In your case, it might look something like...

$csv = "/your/file.csv"; 
$comm = "awk 'BEGIN { FS = \",\" } ; { print $1 }'" .$dd;
exec($comm, $output);
var_dump($output);

(I haven't checked your awk command so far, I suspect it returns the desired result)

相关阅读:
Top