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
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:15 am
Code: Select all
$proccessname = "Epsilon";
$proccesslist = (exec("C:/kill/PS", $poslist));
$key = array_search(Epsilon, $poslist);
if (!$key) {
echo 'Not Found.';
} else {
print ("It was in key $key");
}
It always returns not found, even when I know it is in there. Also, if I print $key, it has no value.
What this is supposed to do is execute ps and grab out the table which says C:\Epsilon\Epsilon.exe plus some space then four characters. Thank you.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Mon Jul 01, 2002 2:22 am
try this for me:
Code: Select all
$proccessname = "Epsilon";
$proccesslist = (exec("C:/kill/PS", $poslist));
if(is_array($poslist)){
echo "poslist is an array";
} else {
echo "poslist is not an array - this is your problem";
}
$key = array_search(Epsilon, $poslist);
if (!$key) {
echo 'Not Found.';
} else {
print ("It was in key $key");
}
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:24 am
It isnt an array. So, how do I fix this? I am somewhat new to this. (a few days =/)
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Mon Jul 01, 2002 2:28 am
try:
Code: Select all
$proccessname = "Epsilon";
exec("C:/kill/PS", $poslist)
or die('failed executing PS');
if(is_array($poslist)){
echo "poslist is an array";
} else {
echo "poslist is not an array - this is your problem";
}
$key = array_search(Epsilon, $poslist);
if (!$key) {
echo 'Not Found.';
} else {
print ("It was in key $key");
}
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:30 am
poslist is an arrayNot Found
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:31 am
do you want the output of ps?
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Mon Jul 01, 2002 2:36 am
ok, now lets try:
Code: Select all
$proccessname = "Epsilon";
exec("C:/kill/PS", $poslist)
or die('failed executing PS');
if(is_array($poslist)){
echo "poslist is an array, here are the values:"
."<pre>\n"
.print_r($poslist)
."</pre><br>\n";
} else {
echo "poslist is not an array - this is your problem";
}
$key = array_search(Epsilon, $poslist);
if (!$key) {
echo 'Not Found.';
} else {
print ("It was in key $key");
}
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Jul 01, 2002 2:36 am
Why don't you check the output of PS by putting:
Code: Select all
echo '<pre>';
print_r($poslist);
echo '</pre>';
after
Code: Select all
exec("C:/kill/PS", $poslist) or die('failed executing PS');
Mac
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Mon Jul 01, 2002 2:37 am
great minds think alike, and post fast
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:38 am
Array ( [0] => Executable Process ID [1] => \SystemRoot\System32\smss.exe 0x9c [2] => \??\D:\WINNT\system32\winlogon.exe 0xcc [3] => D:\WINNT\system32\services.exe 0xe8 [4] => D:\WINNT\system32\lsass.exe 0xf4 [5] => D:\WINNT\system32\svchost.exe 0x1a8 [6] => D:\WINNT\system32\spoolsv.exe 0x1c4 [7] => D:\WINNT\System32\msdtc.exe 0x1e0 [8] => D:\WINNT\System32\svchost.exe 0x258 [9] => D:\WINNT\System32\llssrv.exe 0x26c [10] => c:\apache\APACHE.EXE 0x28c [11] => D:\WINNT\system32\regsvc.exe 0x2a8 [12] => c:\apache\APACHE.EXE 0x2c4 [13] => D:\WINNT\System32\snmp.exe 0x3e0 [14] => D:\WINNT\System32\WBEM\WinMgmt.exe 0x428 [15] => D:\WINNT\System32\inetsrv\inetinfo.exe 0x450 [16] => D:\WINNT\system32\Dfssvc.exe 0x490 [17] => D:\WINNT\Explorer.exe 0x4ec [18] => D:\Program Files\G6 FTP Server\G6FTPSrv.exe 0x478 [19] => D:\WINNT\System32\svchost.exe 0x604 [20] => C:\apache\Apache.exe 0x63c [21] => C:\apache\Apache.exe 0x3c4 [22] => C:\apache\mysql\bin\winmysqladmin.exe 0x4b8 [23] => C:\apache\mysql\bin\mysqld-nt.exe 0x2d4 [24] => C:\Mirc\Invision\Invision2\mirc32.exe 0x1a0 [25] => D:\WINNT\System32\mdm.exe 0x11c [26] => D:\WINNT\system32\NOTEPAD.EXE 0x5f4 [27] => D:\Program Files\Internet Explorer\IEXPLORE.EXE 0x614 [28] => D:\Program Files\Internet Explorer\IEXPLORE.EXE 0x768 [29] => C:\Program Files\AIM95\aim.exe 0x780 [30] => C:\Epsilon\Epsilon.exe 0x12c [31] => c:\apache\php\php.exe 0x2ac [32] => D:\WINNT\System32\cmd.exe 0x488 [33] => C:\kill\ps.exe 0x764 ) poslist is an array, here are the values:
1
Not Found.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Jul 01, 2002 2:39 am
I was obviously a bit slow that time...
Mac
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:39 am
Array
(
[0] => Executable Process ID
[1] => \SystemRoot\System32\smss.exe 0x9c
[2] => \??\D:\WINNT\system32\winlogon.exe 0xcc
[3] => D:\WINNT\system32\services.exe 0xe8
[4] => D:\WINNT\system32\lsass.exe 0xf4
[5] => D:\WINNT\system32\svchost.exe 0x1a8
[6] => D:\WINNT\system32\spoolsv.exe 0x1c4
[7] => D:\WINNT\System32\msdtc.exe 0x1e0
[8] => D:\WINNT\System32\svchost.exe 0x258
[9] => D:\WINNT\System32\llssrv.exe 0x26c
[10] => c:\apache\APACHE.EXE 0x28c
[11] => D:\WINNT\system32\regsvc.exe 0x2a8
[12] => c:\apache\APACHE.EXE 0x2c4
[13] => D:\WINNT\System32\snmp.exe 0x3e0
[14] => D:\WINNT\System32\WBEM\WinMgmt.exe 0x428
[15] => D:\WINNT\System32\inetsrv\inetinfo.exe 0x450
[16] => D:\WINNT\system32\Dfssvc.exe 0x490
[17] => D:\WINNT\Explorer.exe 0x4ec
[18] => D:\Program Files\G6 FTP Server\G6FTPSrv.exe 0x478
[19] => D:\WINNT\System32\svchost.exe 0x604
[20] => C:\apache\Apache.exe 0x63c
[21] => C:\apache\Apache.exe 0x3c4
[22] => C:\apache\mysql\bin\winmysqladmin.exe 0x4b8
[23] => C:\apache\mysql\bin\mysqld-nt.exe 0x2d4
[24] => C:\Mirc\Invision\Invision2\mirc32.exe 0x1a0
[25] => D:\WINNT\System32\mdm.exe 0x11c
[26] => D:\WINNT\system32\NOTEPAD.EXE 0x5f4
[27] => D:\Program Files\Internet Explorer\IEXPLORE.EXE 0x614
[28] => D:\Program Files\Internet Explorer\IEXPLORE.EXE 0x768
[29] => C:\Program Files\AIM95\aim.exe 0x780
[30] => C:\Epsilon\Epsilon.exe 0x12c
[31] => c:\apache\php\php.exe 0x2ac
[32] => D:\WINNT\System32\cmd.exe 0x488
[33] => C:\kill\ps.exe 0x764
)
poslist is an array, here are the values:<pre>
1</pre><br>
Not Found.
Lance705
Forum Newbie
Posts: 17 Joined: Mon Jul 01, 2002 2:15 am
Post
by Lance705 » Mon Jul 01, 2002 2:42 am
forst is sscreen output second is source
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Mon Jul 01, 2002 2:44 am
my guess is that you'd have to put in the entire path, (value of the key) to return anything...
if you knew the wildcards you could set it to find it... but im not good with them
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Jul 01, 2002 2:46 am
Epsilon isn't a value, C:\Epsilon\Epsilon.exe 0x12c is. So,
Code: Select all
foreach ($poslist as $id => $value) {
if (preg_match('/epsilon/i', $value)) {
echo $id;
}
}
might work a bit better.
Mac
Last edited by
twigletmac on Mon Jul 01, 2002 2:46 am, edited 1 time in total.