Page 1 of 2
Problem With array_search()
Posted: Mon Jul 01, 2002 2:15 am
by Lance705
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.
Posted: Mon Jul 01, 2002 2:22 am
by hob_goblin
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");
}
Posted: Mon Jul 01, 2002 2:24 am
by Lance705
It isnt an array. So, how do I fix this? I am somewhat new to this. (a few days =/)
Posted: Mon Jul 01, 2002 2:28 am
by hob_goblin
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");
}
Posted: Mon Jul 01, 2002 2:30 am
by Lance705
poslist is an arrayNot Found
Posted: Mon Jul 01, 2002 2:31 am
by Lance705
do you want the output of ps?
Posted: Mon Jul 01, 2002 2:36 am
by hob_goblin
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");
}
Posted: Mon Jul 01, 2002 2:36 am
by twigletmac
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
Posted: Mon Jul 01, 2002 2:37 am
by hob_goblin
great minds think alike, and post fast

Posted: Mon Jul 01, 2002 2:38 am
by Lance705
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.
Posted: Mon Jul 01, 2002 2:39 am
by twigletmac

I was obviously a bit slow that time...
Mac
Posted: Mon Jul 01, 2002 2:39 am
by Lance705
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.
Posted: Mon Jul 01, 2002 2:42 am
by Lance705
forst is sscreen output second is source
Posted: Mon Jul 01, 2002 2:44 am
by hob_goblin
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
Posted: Mon Jul 01, 2002 2:46 am
by twigletmac
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