Solved

Problem in Perl Script

Posted on 2010-11-10
21
802 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now