Page 1 of 1

[SOLVED] shell_exec

Posted: Thu Feb 15, 2007 8:40 am
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

Posted: Thu Feb 15, 2007 8:55 am
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