HI,

I have to launch an exe from PHP

I tried with this :

$cmd="cmd.exe <MyMsdosCommand> ";
$test=exec(comd);
echo "resultat".$test;

But it doesn't work.
How can I get error message from ms dos (stderr)?

THanX

    <?
    $yaks=system("ipconfig");
    ?>

    but you dont always get the expected results, I find the easiest way is to write a batch file and get php to run that for you

    <?
    $yaks=system("start this.bat");
    ?>

    etc etc

      Howdy...

      Try this:

      exec("whatever.exe", $str);
      for ($i = 0; $i <= count($str); $i++){
      echo $str[$i]."<br>\n";
      }

      Generally, you don't have to run cmd.exe then your command, but if for some reason you do, run cmd.exe /c whatever.exe

      Hope that helps...

      Matt

        im running php iis as isapi.

        no matter what method i try i get "unable to fork" even when executing a simple batch file. ive had to by pass and have asp script execute the bat file and it seems absurd.

        any thoughts?

          the only way ive been able to do this in php/iis/isapi. otherwise i get the fork error. i hope they fix this soon.
          Other than this php/iis/isapi is HOT! really!

          <?
          $asp =("http://localhost/cmd.asp?bat=$bat");
          $fp = fopen($asp, "r");
          fclose($fp);
          ?>

          bat.asp
          <%@ LANGUAGE = "VBSCRIPT" %>
          <%
          Server.ScriptTimeout=1200
          dim vbatpath, cmd, project
          project = request.querystring("bat")
          vbatpath = "c:\bat\"&project&".bat"
          cmd = vbatpath
          set WshShell = Server.CreateObject("WScript.Shell")
          retCode1 = WshShell.Run("cmd /c " & cmd, 1, True)
          set WshShell = nothing
          %>

            I'd almost guarantee that the problem is a Windows permissions one...

            Try setting the permissions on the file that you are trying to execute so that you can get at it.

            Also, having a script asp file like that is very dangerous...
            cmd.asp?bat=del c:/boot.ini

            I'm sure other people would think of much more inventive ways to bring your server to it's knees... there's also no way any ISP would host that site if they knew about that script...

              well since the asp script must execute to localhost.. i can even double check the referring ip.. and its always a dedicated server.... blah blah. but i hate it too.

              i even tried putting the bat file in the system dir and still. unable to fork

              i am read create and write files.. but deleting gives unable to fork error also.
              related? i cant give the directory any looser permissions...

              i think its php a php/isapi bug.

                2 months later

                This one works just fine with me:
                note: $command is the command you're going to execute

                <?php
                $line1 = exec(escapeshellcmd("cmd.exe /c " . $command), $output, $error);
                while (list(,$line) = each($output)){
                echo $line, "<BR>\n";
                }
                if ($error){
                echo "Error code: $error<BR>\n";
                exit;
                }
                ?>

                  3 months later

                  Just wondering if you managed to resolve this. I can't get a batch file to run, I have: iis v.5 php v.4.2.0 windows XP
                  I get repeated unable to fork errors
                  cheers
                  Mike

                    Write a Reply...