Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

can't execute .bat file from php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

can't execute .bat file from php

Postby raphael75 » Mon Feb 04, 2013 4:57 am

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: Select all
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:

Authenticated Users

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

Code: Select all
exec('c:/scripts/labor/scheduled/labor_repost.bat', $out, $retval);
$out = shell_exec('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!
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: can't execute .bat file from php

Postby seandisanti » Thu Feb 07, 2013 12:43 pm

the short answer is that you're doing it wrong. you don't want your server to be able to arbitrarily execute programs based on user input. Personally I'd say just have an output file that you write the store list and dates to, then have a cron job parse it and run your script at regular intervals. and clean the file
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.