0

Using a wamp / php 5.3 I have a weird behavior I'd like your opinion about...

I need to execute some external/shell commands but when I pack them in function the exec() doesn't seem to work anymore...

Exemple: If I do something like:

<?php 
/// some stuff

$getAppCmd = $CLI_CMD." -q -f ".$CLI_REQ_PATH."\getApp.py";
exec($getAppCmd, $apps, $rt);
print_r($apps);

/// other stuff
?>

==> It works just fine :)

BUT, if I try to achieve something more reusable:

<?php
// Some stuff

function getApp(){
    $getAppCmd = $CLI_CMD." -q -f ".$CLI_REQ_PATH."\getApp.py";
    exec($getAppCmd, $apps, $rt);       
    print_r($apps);
    return $apps;
}
$list = getApp();
print_r($list);

//other stuff
?>

==> I'm printing nothing Array() Array()

Am I missing something ?

I've been through some several thread but couldn't find something to guide me, return is supposed to work even if I'm returning an array, and the command is the same inside & outside the function...

I don't get it and need bit of your help.

Thanks !

2

1 Answer 1

1

You're executing the command dirC:\temp instead of dir C:\temp, the space is missing here.

$path = "C:\temp";
$cmd = "dir ".$path;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, actually this was for illustration purpose ^^ Sorry if that spread some doubt. I'm editing the code with the true command it will be more relevant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.