Executing .exe with PHP ( Server side ) ??

Discussion in 'PHP' started by Shimurai, Jul 1, 2010.

  1. #1
    Hello everyone,

    I have a Counter-Strike 1.6 server and I would like to let my server admins to turn ON the server when it crashes, so I investigated a bit to do this using PHP to run an .exe on my server but I'm not very experienced at php and I couldn't figure out how to do this and it's giving me a very big headache cuz I can't find any website/forum that explains how to run a .exe with php..

    I have a dedicated server, with Windows server 2003 sp1 ..

    this is the path to the .exe I want to execute with PHP
    it's a shortcut, and this is the target:

    I would appreciate if someone could tell me the PHP code to run this application through PHP..

    Thanks !!
     
    Shimurai, Jul 1, 2010 IP
  2. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    hmm. This should work;

    
    exec("C:\\HLDS\\schlds.exe");
    
    PHP:
    If not, play around with the path.
     
    Triggs, Jul 1, 2010 IP
  3. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I tried, but it didn't do anything at all..
     
    Shimurai, Jul 1, 2010 IP
  4. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    Place schlds.exe in your public_html folder. Or a folder you know the path to (preferebly the same folder as the .php file), and try to execute from there.
     
    Triggs, Jul 1, 2010 IP
  5. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #5
    nope, doesn't seems to be working..

    i placed the exe at the same location as the PHP file and nothing..
     
    Shimurai, Jul 1, 2010 IP
  6. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #6
    Show your code please.
     
    Triggs, Jul 1, 2010 IP
  7. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #7
    I tried:

    
    <?php
    exec("C:\\xampp\\htdocs\\test\\schlds.exe");
    ?>
    
    Code (php):
    and:

    
    <?php
    exec("schlds.exe");
    ?>
    
    Code (php):
    and

    
    <?php
    exec("./schlds.exe");
    ?>
    
    Code (php):
     
    Shimurai, Jul 1, 2010 IP
  8. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #8
    
    <?php
        if (exec("schlds.exe") || exec("/schlds.exe") || exec("./schlds.exe")){
            die('true');
        }
        echo 'false';
    ?>
    
    PHP:
    Tell me what happens.
     
    Triggs, Jul 1, 2010 IP
  9. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #9
    I got the message "false"
     
    Shimurai, Jul 1, 2010 IP
  10. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #10
    ugh. I suggest telling your friends to download PuTTY. Give them SSH access, and teach them how to execute the program from there.
    I'm not very experienced with exec.
     
    Triggs, Jul 1, 2010 IP
  11. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #11
    how does that works??
     
    Shimurai, Jul 1, 2010 IP
  12. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #12
    do it something like this:
    
    exec('/path/to/your/exe', $result);
    print_r($result);
    
    PHP:
     
    gapz101, Jul 1, 2010 IP
  13. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #13
    this is all I get and exe not running.:

    
    Array ( ) 
    
    Code (php):
     
    Shimurai, Jul 1, 2010 IP
  14. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #14
    hmm, your exe file should be a console app, otherwise you wont get any
     
    gapz101, Jul 1, 2010 IP
  15. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #15
    It is a console..

    The .exe I want to run is a shortcut with the following path:
    
    "C:\HLDS\hlds.exe" -console -game cstrike -ip MYIPHERE -port 27016 +maxplayers 27 +map de_nuke 
    
    Code (php):
    is there any way to get this command working??
     
    Shimurai, Jul 1, 2010 IP
  16. alexeyd

    alexeyd Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    some example? may be it help to you
     
    alexeyd, Jul 2, 2010 IP
  17. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #17
    are you doing it like this?
    
    $exe = "C:\HLDS\hlds.exe -console -game cstrike -ip MYIPHERE -port 27016 +maxplayers 27 +map de_nuke";
    exec($exe, $result);
    print_r($result);
    
    PHP:
     
    gapz101, Jul 2, 2010 IP
  18. Shimurai

    Shimurai Well-Known Member

    Messages:
    186
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #18
    yes, this is what I'm doing:

    
    <?php
    $exe = "C:\\HLDS\\hlds.exe -console -game cstrike -ip HERETHEIP -port 27017 +maxplayers 12 +map de_dust";
    exec($exe, $result);
    print_r($result);
    ?>
    
    Code (php):
    and all i get is Array ( )
     
    Shimurai, Jul 2, 2010 IP