Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: unpacking wmic command's unicode output

by cmv (Chaplain)
on Nov 13, 2008 at 18:32 UTC ( [id://723481]=note: print w/replies, xml ) Need Help??


in reply to unpacking wmic command's unicode output

goibhniu-

I wrestled with wmic a while back and came up with a very perl-friendly way to access the data.

The key is using list /format:value on the command line.

-Craig

use strict; use Tk; use Data::Dumper; my %DATA; # Get info via wmic (not available on all versions of windows)... my @data = split(/^\s*\cM\n/m, `wmic process list /format:value`); shift(@data); pop(@data); # Remove first/last blank lines my %procs; # Iterate through each element... foreach my $p (@data) { $p =~ s/\cM//g; # Grrrr, rotten windows my %child = split(/[=\n]/, $p); # Hashify information $procs{$child{ProcessId}} = \%child; } print Dumper(\%procs), "\n";

Replies are listed 'Best First'.
Re^2: unpacking wmic command's unicode output
by goibhniu (Hermit) on Nov 13, 2008 at 20:38 UTC

    Very good, but it doesn't quite meet our use case. Our Admin knows the exe name he's looking for, but there could be several running at one time differentiated by the command line arguments. Task Manager shows them all, but not the command line arguments, so the admin doesn't know which to kill. wmic process list full produces outpout similar to your /format:value, so we did things like wmic process list full | find /i "ourprog.exe", but when more than one was running, couldn't tell the pid (because it's on another line). Just plain wmic process put all the data on one line so that's what I was thinking about and it colored my design space.

    I actually like your hash-ification better, and if I were writing a larger program (I see you have Tk in your use statements) that's exactly how I'd go.

    Thanks again.


    #my sig used to say 'I humbly seek wisdom. '. Now it says:
    use strict;
    use warnings;
    I humbly seek wisdom.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://723481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-25 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found