- 论坛徽章:
- 0
|
请perl的前辈们帮助我!!谢谢!!!
我给你给例子好了,首先请安装Win32: rocess::Info这个模块,可以在CPAN找到,也可以用ActivePerl自带的ppm安装Win32-Process-Info
,我给出的这个例子在运行后会自动运行记事本notepad.exe,然后循环判断进程列表里有没有notepad.exe,如果有,就打印notepad is running,否则打印notepad is not running并且运行另外一个程序(这里的另外一个程序也设成了notepad.exe)
- #!/usr/bin/perl
- #cnhackTNT@perlchina.org
- use Win32::Process::Info;
- $execer='notepad.exe';
- $otherProcess=$execer;
- system('start '.$execer);
- $pi = Win32::Process::Info->;new ();
- while(1){
- foreach $proc ($pi->;GetProcInfo ()) {
- if($$proc{'Name'} eq $execer){
- $runORnot=1;
- last;
- }else{
- $runORnot=0;
- }
- }
- if($runORnot){
- print "$execer is running....\n";
- }else{
- print "$execer in not running,I will call process $otherProcess\n";
- system('start '.$execer);
- }
- }
复制代码 |
|