Question

I am attempting to load a webpage on my own server which will run a .bat script (on the same server) as below.

When I access the page, called test.php, it display the 'DO IT!' button and when I press it, it just display the content on the .bat file rather than executing it on the server...

What do I need to configure on the server, I assume in the PHP settings, to force it to run the script rather than just display it on the webpage?

For the purpose of the question, I am happy about the security implications of what I am doing.

I am running a Windows machine with IIS and PHP.

<html>
    <head>
        <title>Restarting</title>
    </head>
    <body>
    <?php
        if(isset($_POST['submit']))
        {
            echo exec('c:\scripting.bat');
            echo "Done!";
        } else {
            // display the form
    ?>
    <form action="" method="post">
    <input type="submit" name="submit" value="DO IT!">
    </form>
    <?php
        }
    ?>
    </body>
</html>
Was it helpful?

Solution

I think that the echo exec('c:\scripting.bat'); line it's causing you the problem. Try to just execute it without the echo statement.

If you trying to see the output of the function, you must use the second functions parameter: &$output, acording to the documentation itself. See it in the docs here.

I hope it will be useful to you! :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top