"Syntax error, Unexpected '&'" when calling exec

Asked

Viewed 36 times

-1

<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Executar</title>
</head>
<body>
    <?php
        exec( 'Done.exe', &$resultado);
        echo $resultado;
    ?>
</body>
</html>

The command is not working exec, how do I enable it?

  • 2

    I removed the HTML, CSS, Javascript and Node tags because I saw no relation to the question. If there is a relationship, I recommend that you edit the question in detail.

  • 2

    And on the basis that you claim that the exec isn’t working? Did you make a mistake? Which one? What Done.exe does? Is it in the same directory? Is the user allowed to run it? What are the latest messages in your PHP server’s log file?

  • Parse error: syntax error, Unexpected '&', expecting ')' in C: xampp htdocs Execute index.php on line 8

  • The file is in the same folder as index.php

  • 1

    To pass a variable as a reference in PHP only the function argument needs to indicate the &. You don’t need to indicate this in the function call, so just do exec('Done.exe', $resultado)

  • The Done.exe file runs a C++ game that I programmed and the error to give is this: syntax error, Unexpected '&', expecting ')' in C: xampp htdocs Run index.php on line 8

Show 1 more comment

1 answer

1

Vide documentation:

Note: There is no reference signal in function call - only in function settings. The function definitions alone are sufficient to pass the argument by reference. From PHP 5.3.0 you will receive a "call-time pass-by-Ference" alert that is obsolete when using & na in function calls: foo(&$a);. From PHP 5.4.0, passing by reference in the call has been removed, and using it will cause a fatal error.

That is, only the signature of the function that must indicate that the passage will be made by reference and not by value. From version 5.4 on calls using the character & will cause a syntax error as you got.

That is, on the call from exec just do:

exec('Done.exe', $resultado);

Even if the variable does not exist in the context it will be created to receive the value defined by the function.

  • If I put this on a server, it will run on the server machine or on the person’s computer?

  • 1

    @Schillerdrummond On the server, always.

  • Now how will I infect my victims with this command :(

  • @Schillerdrummond won’t go...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.