php and .bat

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benyboi
Forum Commoner
Posts: 80
Joined: Sat Feb 24, 2007 5:37 am

php and .bat

Post by benyboi »

is there a way for me, in a .php page when loaded, to make it run a .bat file on the server? hope you understand...

thanks for your help!
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

There is a way you can do it, just dont know the exact syntax. Something like system <i>filename.bat</i>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

benyboi
Forum Commoner
Posts: 80
Joined: Sat Feb 24, 2007 5:37 am

Post by benyboi »

ok, thanks

Code: Select all

system($command[$return_var]);
would i be able to put a path to a .bat file in the $command vairable? I tried but it just gives a blank page?

thanks
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

The backtick operator is a nicer way of saying system()

Code: Select all

$var = 'foo'; echo `C:\whatever\someFile.bat cmd line args $var`;
Be very careful with variables in the command line because if the user can control them in anyway i.e. via $_GET, $_POST or indirectly via a database then they might be able to run nasty commands.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

benyboi wrote:I tried but it just gives a blank page?
Blank pages almost suggest a parse error of some sort.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Use error_reporting(E_ALL); at the top of your page
and did you tried using exec('your_file.bat');
Post Reply