Solved

Problem in Perl Script

Posted on 2010-11-10
21
816 Views
Last Modified: 2012-05-10
Hello,
I have a part of a perl script and i just want to figure it out that when we run this script we not getting full output. Is there any problem in this script?
Is there any issue with command which use in this script. Can we use win32:iproc  instead? and how?
I am attaching output file. some of the output are missing. how we can get those as well.
I am attaching part of the script and its output please let me know asap.
Thanks


script.txt
output.txt
0
Comment
Question by:izharkhan
  • 12
  • 9
21 Comments
 
LVL 16

Accepted Solution

by:
jmatix earned 500 total points
ID: 34104942
Try this script:
use Win32::OLE qw( in );
$svc=Win32::OLE->GetObject("winmgmts:root\\cimv2");
$query="select * from win32_process";

$cproc=$svc->execquery($query);

#print $cproc->count;

foreach my $Proc (in ( $cproc ))
{
	print $Proc->ProcessId, "\t";
	print $Proc->Caption, "\n";
}

Open in new window

0
 

Author Comment

by:izharkhan
ID: 34106043
Hey Jmatix,
Thanks for your quick reply...
Just for info, that this script is a part of a whole script....and only this part give that output.
I just need to ask that if i will change this part of a script is that gonna any effect on whole script?
I really dont know much about perl scripting. also if you can tell how i can run this and check in server..i will appreciate..


Also if you can give me a script with "win32:iproc" instead that will be helpful for me.

Thanks
Izhar
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34106128
Adding this script to your existing script should not affect anything else. Or you can put this into a separate file, say, win32procs.pl and call it from the parent script as:

system ("perl.exe", " win32procs.pl");
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:izharkhan
ID: 34106417
Hey Jmatix,
Thanks for your help now i can run this script. its work fine.
But the thing is we are not allow to use WMI. I need to use other command for example "win32:iproc". Can you make this one with the help of this command or can change with any other accept WMI.

Thanks
Izhar
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34107945
I don't have win32:iproc installed. If you can get the Perl module Win32::Process::List you can do this:

  use Win32::Process::List;
  my $P = Win32::Process::List->new();  constructor
  my %list = $P->GetProcesses();        returns the hashes with PID and process name
  foreach my $key ( keys %list ) {
        # $list{$key} is now the process name and $key is the PID
        print sprintf("%30s has PID %15s", $list{$key}, $key) . "\n";
  }

Get the module at: http://search.cpan.org/dist/Win32-Process-List-0.09/List.pm

0
 

Author Comment

by:izharkhan
ID: 34111927
Hey Jmatix,
Thanks for your help......
In last script you posted i didnt get idea about that...how i can use it :)
and again if you can help me to make a small script with "win32:iproc" it will be great.
thanks in advance :)
Thanks
Izhar
0
 

Author Comment

by:izharkhan
ID: 34112877
Hello,

when i run this script in windows xp its give me all info......
but when i try to run this in server 2003 at that time its giving me error message
" Can't locate object method "Getobject" via package "win32::OLE" at C:\perl\test.pl line 2."
In server 2003 i am using perl, version 5.005_03
what i can do now???
please let me know
Thanks
Izhar
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34113002
Win32::OLE module may not be installed on the server. See if you can get that installed from CPAN.

http://search.cpan.org/~jdb/Win32-OLE-0.1709/lib/Win32/OLE.pm
0
 

Author Comment

by:izharkhan
ID: 34115093
Hey Jmatix,
its work fine.......
still if i can get with iproc that will be great becaz here everyone ask for that actually.........
thats why i need to find out that way if u can help me for that i really appreciate
Thanks
izhar
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34115281
If you have Win32::IProc installed, you can try:
use Win32::IProc;

$pobj = new Win32::IProc or die "Unable to create proccess object: $!\n";
$pobj-> EnumProccesses(\@processlist) or 
   die "Unable to get process list:$!\n";

foreach $process (@processlist){
  $pid  = $process->{ProcessId};
  $name = $process->{ProcessName};
  print "$pid\t$name\n";
}

Open in new window

0
 

Author Comment

by:izharkhan
ID: 34115428
Hey Jmatix,
you are really great. :)
i just have one more concern.....
is that any ways that we can write same script with win32::process with your own way.....like your logic with using Win32::Process::Info??? not same as I uploaded....
if you can write that one that will be helpgfull to me....
really really really thanks
Izhar :)
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34115558

use Win32::Process::Info qw{NT};
$pi = Win32::Process::Info->new ();
@info = $pi->GetProcInfo ();
print ${$_}{ProcessId}, "\t", ${$_}{Name}, "\t", ${$_}{ExecutablePath}, "\n" for @info;

Open in new window

0
 

Author Comment

by:izharkhan
ID: 34115869
hey Bro,

C:\Perl>process.pl
Can't locate Win32/Process/Info.pm in @INC (@INC contains: C:/Perl/site/lib C:/P
erl/lib .) at C:\Perl\process.pl line 1.
BEGIN failed--compilation aborted at C:\Perl\process.pl line 1.



I am getting this error :(
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34115933
You need to install the Perl module Win32::Process::Info from CPAN.

0
 

Author Comment

by:izharkhan
ID: 34121958
Hey Bro,
I am able to run process::iinfo script which i upload here....but i cant run this one dont know why its showing same error.......
what to do now?
0
 

Author Comment

by:izharkhan
ID: 34122341
Can't locate object method "new" via package "win32::process::Info"
 forgot to load "win32::process::Info"?) at C:\Perl\test.pl line 2.
????
0
 

Author Comment

by:izharkhan
ID: 34136557
Hey Jmatix,

what i can do with this error. i tried to install win32::process::info but still getting this error
Can't locate object method "new" via package "win32::process::Info"
 forgot to load "win32::process::Info"?) at C:\Perl\test.pl line 2.

May be i am doing mistake,
first i run this command
perl -MCPAN -e shell
then
install win32::process::info
its says sucess
then i exit from cpan
then in command propt
c:\perl>test.pl

this is correct way to run script or still doing mistake?

can you help me please :)
thanks
Izhar
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34138004
Check if you are using the right case -  Win32::Process::Info and not win32::process::Info.
0
 

Author Comment

by:izharkhan
ID: 34138106
Thanks jmatix,
That was my mistake :)
now i can run that script...
can you tell me what command i can use to download IProc module?
 becaz i tried this command
isntall Win32::IProc
but its says failed to install module

Test Summary Report
-------------------
t/Test-MultiProcess.t (Wstat: 65280 Tests: 1 Failed: 1)
  Failed test:  1
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 3 tests but ran 1.
Files=1, Tests=1,  0 wallclock secs ( 0.02 usr +  0.03 sys =  0.05 CPU)
Result: FAIL
Failed 1/1 test programs. 1/1 subtests failed.
dmake.exe:  Error code 255, while making 'test_dynamic'
  DBRIAN/Test-MultiProcess-0.01.tar.gz
  C:\STRAWB~1\c\bin\dmake.exe test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
  reports DBRIAN/Test-MultiProcess-0.01.tar.gz
Running make install
  make test had returned bad status, won't install without force
Failed during this command:
 DBRIAN/Test-MultiProcess-0.01.tar.gz         : make_test NO
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34138525
I could not find Win32::IProc module anywhere to install. It looks like it is no longer being maintained by anyone. From what I understand it used to be available here:

http://jenda.krynicky.cz/

But sadly it is removed from there too.

0
 

Author Comment

by:izharkhan
ID: 34138640
so that means i cant run IProc anymore????
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question