Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2013, 12:50 PM   PM User | #1
Raphael
New Coder

 
Join Date: Mar 2009
Posts: 70
Thanks: 3
Thanked 3 Times in 3 Posts
Raphael is an unknown quantity at this point
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!
Raphael is offline   Reply With Quote
Old 02-04-2013, 05:18 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 362 Times in 361 Posts
sunfighter is on a distinguished road
Does this help?
http://www.ehow.com/how_6900969_run-batch-file-php.html
sunfighter is online now   Reply With Quote
Old 02-04-2013, 09:08 PM   PM User | #3
Raphael
New Coder

 
Join Date: Mar 2009
Posts: 70
Thanks: 3
Thanked 3 Times in 3 Posts
Raphael is an unknown quantity at this point
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.
Raphael is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53 PM.


Advertisement
Log in to turn off these ads.