Previous Next

Thread: Why I can't exec batch file? ???

Last post 08-22-2008 7:26 AM by luxus. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 05-05-2008, 11:38 PM

    • toeh101
    • Not Ranked
    • Joined on 04-21-2008, 8:48 AM
    • Posts 3
    • toeh101

    Why I can't exec batch file? ???

    Hi,
    I've tried to use PHP exec() to execute DOS command.
    It works with command exec("md example_dir") .
    But when I put test.bat in same directory and run PHP with exec("test.bat") , it doesn't work. No error showed but not work.

    Anyone can help me?

    Thanks.

  • 05-06-2008, 10:29 AM In reply to

    • brashquido
    • Top 25 Contributor
    • Joined on 05-22-2006, 12:31 AM
    • Australia
    • Posts 153
    • IIS MVPs
    • brashquido

    Re: Why I can't exec batch file? ???

    You'll need to specify that you wish to use the Windows command line to execute your batch file. Have you tried something like exec("cmd.exe /c test.bat") ?

    ----------------
    Dominic Ryan
    Microsoft IIS MVP
    www.iis-aid.com
    My IIS articles
    My PHP articles
    My How-to guides
  • 05-06-2008, 12:32 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 988
    • anilr

    Re: Why I can't exec batch file? ???

    Also, the current working directory of the php process (in the fastcgi case) is not the application/vdir root, but the directory from where php is run, so use a fully qualified path.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 08-22-2008, 6:46 AM In reply to

    • luxus
    • Not Ranked
    • Joined on 08-22-2008, 5:09 AM
    • Posts 2
    • luxus

    Re: Why I can't exec batch file? ???

    Hi,

    I think that this is not correct.

    PHP uses cmd.exe /c to execute the value passed to exec. I've the same problem and I am sure that the cwd of my script is used.

    Example:

    - start_test.bat is my batch i want to execute
    - My PHP-script and the start_test.bat are located in C:\Inetpub\wwwroot\test

    When call "type start_test.bat" (PHP executes "cmd.exe /c type start_test.bat") by this PHP code:
    $a = array();
    exec("type start_test.bat", $a);
    print_r($a);

    I get the lines of start_test.bat

    When I call "start_test.bat" (PHP executes "cmd.exe /c start_test.bat") the result is NULL.

    How can I get batch files working?

     

  • 08-22-2008, 7:26 AM In reply to

    • luxus
    • Not Ranked
    • Joined on 08-22-2008, 5:09 AM
    • Posts 2
    • luxus

    Re: Why I can't exec batch file? ???

    Hi,

    i read the cmd /c thing over. This is working.

    You can run batch files by calling "cmd /c yourbatch.bat" so PHP will exec "cmd /c cmd /c yourbatch.bat".

    But why is this nessecary? On PHP/Apache on W32 calling batch files works without the double cmd /c?

Page 1 of 1 (5 items)
Page view counter