For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2008 > exec









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author exec
Jean Pierre Daviau

2008-01-22, 8:08 am

Hi everyone,

I am trying to capture the output from an exe that takes a file
and output the counted words.
ex:
Usage: krx60410 < file
Total Words : 103
8 de
7 la
4 culture
4 qui
-------- snip ------------

I tried the folowing wich doe not work has you gessed.

$input = file($fichier);
$output = exec("tree_words.exe < $input", fgets(STDOUT));
echo $output;

--
Thanks for your attention.

Jean Pierre Daviau
--
windows Xp
asus p4 s533/333/133
Intel(R) Celeron (R) CPU 2.00 GHz
Processor Radeon7000 0x5159 agp


Anze

2008-01-22, 7:07 pm

> $output = exec("tree_words.exe < $input", fgets(STDOUT));

Second parameter should be an array, you will get the output in it. For
instance:

$a=array();
$output = exec("tree_words.exe < $input", $a);
var_dump($a);

Or use passthru().

Be _very_ careful to validate $input variable!!!!!!

Anze

Jean Pierre Daviau

2008-01-23, 8:06 am

I have found that it was the indirection < that
creates the bug.

I tried to escape it \
tried to use oblique quotes `<`
dont works.

Any clue?



"Anze" <anzenews@volja.net> a écrit dans le message de news:
9Rnlj.5587$HS3.233379@news.siol.net...
>
> Second parameter should be an array, you will get the output in
> it. For
> instance:
>
> $a=array();
> $output = exec("tree_words.exe < $input", $a);
> var_dump($a);
>
> Or use passthru().
>
> Be _very_ careful to validate $input variable!!!!!!
>
> Anze
>



The Beloved

2008-01-23, 7:06 pm

On Wed, 23 Jan 2008 08:26:39 -0500, "Jean Pierre Daviau"
<Once@WasEno.ugh> wrote:

>I have found that it was the indirection < that
>creates the bug.

[color=darkred]

Create the command string outside the exec command ?

$mycommand = "tree_words.exe ".char(60)." ".$input;
$output = exec($mycommand, $a);

Not tested.

--
....For Those Not Te Be Forgotten...
Jean Pierre Daviau

2008-01-23, 7:06 pm


"The Beloved" <maybe@one.day> a écrit dans le message de news:
4fnep397av4h88u656rc6jas1b2dqkdu8l@4ax.com...
> On Wed, 23 Jan 2008 08:26:39 -0500, "Jean Pierre Daviau"
> <Once@WasEno.ugh> wrote:
>
>
>
> Create the command string outside the exec command ?
>
> $mycommand = "tree_words.exe ".char(60)." ".$input;
> $output = exec($mycommand, $a);


Does not work


C.

2008-01-24, 8:05 am

On 22 Jan, 11:55, "Jean Pierre Daviau" <O...@WasEno.ugh> wrote:
> Hi everyone,
>
> I am trying to capture the output from an exe that takes a file
> and output the counted words.
> ex:
> Usage: krx60410 < file
> Total Words : 103
> 8 de
> 7 la
> 4 culture
> 4 qui
> -------- snip ------------
>
> I tried the folowing wich doe not work has you gessed.
>
> $input = file($fichier);
> $output = exec("tree_words.exe < $input", fgets(STDOUT));
> echo $output;
>


I/O redirection expects a file - so unless $fichier is the name of a
file containing another filename you're doing something whacky here
which will not work. Surely you mean to do this:

$output = exec("tree_words.exe < $fichier", $real_output);

I have no idea what you're trying to do with fgets(STDOUT) which
doesn't even make sense on its own in PHP (the std streams exist but
have to be explicitly opened - there is no guarantee that the resource
will have a specific value therefore cannot be referenced using a
constant.

C.

Jean Pierre Daviau

2008-01-24, 7:07 pm

[color=darkred]

Thanks to all of you. You helpeed me to stick at it

$output = exec("tree_words.exe < $THIS - >input", $a);


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com