[SOLVED] shell_exec

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
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

[SOLVED] shell_exec

Post by mikeeeeeeey »

afternooooooon.

at the moment I'm using:

Code: Select all

print_r("<pre>" . shell_exec(set) . "</pre>");
to run the command SET, a DOS command. When I run this, I'm greeted with a big dump, similar to when you run SET in DOS.

At the moment, I'm only trying to wedge 'SystemRoot' out of there, but to no avail I've triied shell_exec(set=SystemRoot), shell_exec(set['SystemRoot']), and I can't figure out how to access it (whether its an array, an object, super global, yada yada).

Anyone have any ideas? :?

Thanks in advance guys :D
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

Post by mikeeeeeeey »

I know it's pretty daft posting on my own topic but I thought if anyone has the same problem, they can check it out.

I was using...

Code: Select all

print_r("<pre>" . shell_exec(set) . "</pre>");
but if you need any subsidaries of SET use...

Code: Select all

print_r("<pre>" . shell_exec('set systemroot') . "</pre>");
NOTE the apostrophe's. They are so damn important.

and, something which I also just found useful, if you output the command above you'll get:

Code: Select all

SystemRoot=YourSystemRoot
but by using...

Code: Select all

$fullpath = shell_exec('set systemroot');
$cutoff   = strpos($fullpath,"=")+1;
$actual   = substr($fullpath,$cutoff,strlen($fullpath)-$cutoff);
you'll be able to get the system root with the label shaved off :D
Post Reply