2

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>

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, the echo was causing the output to display on the webpage, but the problem with it not working was that the .bat appears to have to be in the inetpub folder from where the page is... Thanks!
same problem for me. are you fix your problem ? to call the bat file from web page? @omega1
Hello, Yes I solved it, the .bat file had to be inside the inetpub folder and then it worked. I don't know if it could work having the .bat folder located elsewhere, but this solved my needs.
And in the code in my question, remove the echo statement in front of the exec command.

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.