Jump to content

2 exec() functions, one works the other doesn't


Recommended Posts

I have two functions that execute an exe program (personal project for a minecraft back end.) Windows only.



First one will execute the sending of commands (THIS ONE WORKS)

	/* check to see if admin is sending commands to terminal via web */
    if(isset($_POST['command'])) {
        $content = $_POST['command'];
        try {
        } catch ( Exception $e ) {
            die ($e->getMessage());

This has been a head scratcher for most the week - any help or suggestions would be great!! thanks!!



	<div id="commands">
            <div id="command_input">
                <form method="post" id="commandForm" action="index.php">
                    <label for="command" >Console Command:</label><br/>
                    <input type="text" name="command" autofocuS/>
                    <input type="submit" name="submit_command" value=" >> " /> &nbsp;                
                    <input type="button" value="Refresh page" onclick="location.reload(true);" />


This is used to start the server

        try {
                exec(SERVER_DIR.'startServer.bat 2>&1' ,$output);  
        } catch( Exception $e ) {
            die ($e->getMessage());


	<div id="server_control">
                        <form action="index.php" method="post">
                            <input type="submit" value="START" id="startServerBtn" name="startServerBtn"/>

MCCOMMANDS.EXE will work from both browser(php) and file manager(tested)

the STARTSERVER.EXE will NOT work from browser(php), but will work from file manager


The function IS being accessed - debug is showing it going there, and it seems to be running

Both exe's are in the same folder

Edited by Klyx99
code tags missing
Link to comment
Share on other sites

O programmer err - script above is fine. My server was lagging and was able to see if "flash" up and disappear. Apparently there is an issue with the batchfile - paths need to be absolute, The script has it relative, thus why it works from file manager, but not the browser.


I'll leave the code up for anyone that wants to make something similar as reference.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.