Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts

    can't execute .bat file from php

    We have a web portal in a WIMP environment. There is a web page that users can fill out a form. When the form submits I need it to create and execute a batch file on the server that is in a folder outside the wwwroot folder.

    What happens is the user submits the form & the php is able to create the .bat file in c:/scripts/labor/scheduled/labor_repost.bat, no problem. The contents of the batch file is a single line that looks like:

    Code:
    c:\scripts\labor\scheduled\cscript.exe c:\scripts\labor\scheduled\labor.vbs /store_list:"store1;store2" /start_date:"2013-01-21" /end_date:"2013-01-24"
    If I execute the .bat file from the command line manually it works perfectly.

    The cscript.exe, labor.vbs, and labor_repost.bat files are all in the same folder. In testing, I've tried setting permissions on all these files and the folder they're in to allow these users full control:

    Everyone
    Authenticated Users
    IUSR
    System
    Users


    However, nothing I try from PHP is able to execute the .bat file. I have tried:

    exec('c:/scripts/labor/scheduled/labor_repost.bat', $out, $retval);
    $out = shell_exec('c:/scripts/labor/scheduled/labor_repost.bat');
    system('c:/scripts/labor/scheduled/labor_repost.bat');

    $ws = new COM('WScript.Shell');
    $w = $ws->Run('c:/scripts/labor/scheduled/labor_repost.bat', 0, false);

    I've also tried various other combinations of this by including "psexec" and "cmd /c".

    None of these will execute the batch file - no matter which one I try, nothing happens. If I echo back the return value from the batch file, it will just echo back the contents of the file. I don't get any error messages.

    Is it possible that it's a permissions issue? If so, what would need permission to what?

    We checked the antivirus logs and it doesn't appear to be that.

    Please help. Thank you!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by sunfighter View Post
    I'm way beyond such a simple tutorial. I've tried each of the lines in the php code above with and without:

    cmd
    cmd /c
    psexec

    I think it might be a permissions issue of some sort or the fact that the batch file the php is trying to execute is in a folder outside the wwwroot folder. But I don't know.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •