Another command that might work for you is the ls command and a listConnections command... I've used this recentling in finding the number of materials assigned to the selected polygon objects. Here's the basics of what I did, you probably want to use a differnt type than mesh.
string $evalList[] = ls -selection -objectsOnly -dagObjects -exactType "mesh"
;
listConnections -source true -type shadingEngine $evalList;
This should return the shaders assigned to the current polygon selection per selected object... I then use the stringArrayRemoveDuplicates command to narrow this down to uniques...
If anyone has a better way of doing this, please let me know
Thanks