server per php neustarten

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • server per php neustarten

    hallo,

    ich hab folgendes problem: ich würde gerne eine datei mittels php ausführen um einen reboot durchzuführen. dazu habe ich eine
    reboot.bat
    [COLOR=red]c:\windows\system32\shutdown.exe -r -t 10[/COLOR]

    welche auch wenn man sie so ausführt wunderbar klappt und eine reboot.php
    [COLOR=red]exec('reboot.bat',$var);
    print_r($var);[/COLOR]

    aber wenn ich die php datei öffne erscheint nur
    [COLOR=red]c:\pfad\pfad>windows\system32\shutdown.exe -r -t 10[/COLOR]

    ...aus irgend einem grund scheint er die datei nicht auszuführen sondern den befehl nur auszgeben.
    rechte für cmd.exe habe ich bereit vergeben.

    (Win 2k3 IIS6, PHP 5.1.2)

  • #2
    Re: server per php neustarten

    PS: Wieso führst du nicht den befehl: c:\windows\system32\shutdown.exe -r -t 10 direkt aus, anstatt ihn in eine *.bat zu stecken ?

    Habe das hier mal selbst in einem anderen Forum gefunden:
    PHP-Code:
    <html>
    <head>
    <title>Programme auf dem Server starten</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF">

    <?

    function execInBackground($path, $exe, $args = "") {
    global $conf;

    if (file_exists($path . $exe)) {
    chdir($path);
    if (substr(php_uname(), 0, 7) == "Windows"){
    pclose(popen("start \"bla\" \"" . $exe . "\" " . escapeshellarg($args), "r"));
    } else {
    exec("./" . $exe . " " . escapeshellarg($args) . " > /dev/null &");
    }
    }
    }

    $pfadzurapplikation = "C:/Programme/Internet Explorer/"; // Backslashes durch slashes ersetzen, muss mit slash abschließen
    $programm = "IEXPLORE.EXE";
    $parameter = "";
    execInBackground ($pfadzurapplikation, $programm, $parameter);
    ?>

    </body>
    </html>
    Damit soll es angeblich funktionieren eine *.bat auszuführen.


    Sers
    Der Boris
    Zuletzt geändert von boris-schneider; 28.04.2006, 07:34.

    Kommentar


    • #3
      ja die seite hatte ich auch schon mal überflogen, aber ich denke nicht das es unmittelbar an exec liegt.

      nehm ich statt exec einfach: echo `reboot.bat`; kommt auch nur der befehl ausgegeben.

      ???

      Kommentar


      • #4
        Ich denke es liegt daran, das man *.bat Dateien ja auch nur auf Windowsebene ausführen kann und exec ja nur ausführbare dateien startet, sprich *.exe dateien und/oder weil sie mit einer alias versehen sind, darum bekommst du auch nur den geparsten Inhalt zu sehen da PHP annimmt es sein eine ganz normale Textdatei!

        PS: Wieso führst du nicht den befehl: c:\windows\system32\shutdown.exe -r -t 10 direkt aus, anstatt ihn in eine *.bat zu stecken ?

        EDIT: hier nochmal ein Beitrag aus den Comments im php.net manual
        PHP-Code:
        Starting batch or exe files (from a local Apache server 1.3.24 with PHP 4.3.1) to be executed within WinXP SP2 and having the program running in background - which certainly is tricky.

        I figured this peace of code makes it very possible.
        Instead of using exec() I prefered popen() adding the parameter /b which makes it run in the background, thus having PHP script continued to be interpreted contrary to be hanging in the process.
         
        <?php
        function callTool ($path,$file) {
           
        chdir($path); $call $path.$file;
           
        pclose(popen('start /b '.$call.'''r'));
        }

        // -- Call tool1 -----
        $location "c:\path\to\desired\folder";
        $filename "\tool1.exe";
        callTool($location,$filename);

        // -- Call tool2 -----
        $location "c:\path\to\desired\folder";
        $filename "\tool2.bat";
        callTool($location,$filename);

        // -- Call tool3 -----
        $location "c:\path\to\desired\folder";
        $filename "\tool3.com";
        callTool($location,$filename);
        ?>

        This example assumes that the Apache properties locally has bin told to 'allowe this server to interact with desktop' which on WinXP is to be set under Start > Run > services.msc - next, right click "Apache...", select properties and click on the 'login tab'.

        Hope someone to benefit out of this stuff.
        Zuletzt geändert von boris-schneider; 28.04.2006, 07:43.

        Kommentar

        Lädt...
        X