UnstoppableDrew has asked for the wisdom of the Perl Monks concerning the following question:
My problem: I have a perl script that is a test harness. It starts up some clients using fork/exec and then does stuff. This much all works great. Now there is a new requirement. I need to start a matlab RMI server, which is essentially just calling java with the matlab class. The problem is there isn't a graceful way to shutdown the matlab server, you have to kill it. Perl under windows doesn't return a true pid when it forks, and it changes upon exec anyway. My solution was to use Win32::OLE and access the process info. Since it's possible there will be other java processes running I tried to find the pid's of all the java.exe processes and save them. I then fork/exec the rmi server, and look again to find the new java process. However if you have Win32::OLE in your script and fork it throws an unhandled exception. There was a bug filed against Active perl about this back in 2005, but it's clearly not fixed yet.
I tried various methods of load win32::ole, do my thing, unload it, and load it again for the second pid scrape, but its just not working.
Here's the most recent iteration of the code:
There has got to be a better way to do this.sub scrape_java_pids { use Win32::OLE; my $CLASS = "winmgmts:{impersonationLevel=impersonate}\\\\.\\Root\\c +imv2"; my $WMI = Win32::OLE->GetObject( $CLASS ) || die "Error - failed to +instantiate Win32::OLE object: $!\n"; my %jpid; foreach my $Proc ( $WMI->ExecQuery("SELECT * FROM Win32_Process WHER +E Name = 'java.exe'") ) { $jpid{ $Proc->{ProcessID} } = 1; } Symbol::delete_package("Win32::OLE"); # fork & win32::ole don't pla +y nicely. delete $INC{'Win32/OLE.pm'}; $WMI=""; return %jpid; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Windows + Win32::OLE + fork = Hell
by BrowserUk (Patriarch) on Oct 03, 2007 at 18:18 UTC | |
|
Re: Windows + Win32::OLE + fork = Hell
by UnstoppableDrew (Sexton) on Oct 03, 2007 at 16:49 UTC | |
|
Re: Windows + Win32::OLE + fork = Hell
by renodino (Curate) on Oct 03, 2007 at 16:55 UTC | |
|
Re: Windows + Win32::OLE + fork = Hell
by cmv (Chaplain) on Oct 03, 2007 at 22:40 UTC | |
by cmv (Chaplain) on Oct 04, 2007 at 20:38 UTC | |
|
Re: Windows + Win32::OLE + fork = Hell
by UnstoppableDrew (Sexton) on Oct 04, 2007 at 16:31 UTC | |
|
Re: Windows + Win32::OLE + fork = Hell
by Cop (Initiate) on Oct 03, 2007 at 18:12 UTC | |
by UnstoppableDrew (Sexton) on Oct 04, 2007 at 14:55 UTC |