> Is there a way to identify when the output is being presented in a separate window (such that I could change the code so that the "Enter to close window:" prompt only appears in these cases)?
Yes you can, and the solotion was already at pm: Re: Re: Re: Parent process name but is slow because it processes all PIDs to get one matching $$ (I wonder if this can be shortened..) using the cpan Win32::Process::Info module.
Here an adapted solution:
use strict; use Win32::Process::Info; my $pihandle = Win32::Process::Info->new(); my @procinfo = $pihandle->GetProcInfo(); my $ParentPID; my %ProcNames; foreach my $PIDInfo (@procinfo) { $ProcNames{$PIDInfo->{ProcessId}} = $PIDInfo->{Name}; if ($PIDInfo->{ProcessId} == $$) { $ParentPID = $PIDInfo->{ParentProcessId}; last; } } print "Parent's name is [", $ProcNames{$ParentPID}, "]\n"; if ( $ProcNames{$ParentPID} eq 'OpenWith.exe' or $ProcNames{$ParentPID +} eq 'explorer.exe') { print 'Press ENTER to close the window: '; <>; } else{ print "..exiting normally\n"; }
Calling the above program from command line (I always use the longhish form: perl program.pl because I do not want to mess with assoc and friends and .pl is associated just with the editor ;) the program exit directly:
Discipulus@works:D>perl parentpid01.pl Parent's name is [cmd.exe] ..exiting normally
But right clicking the file and using Open with and browsing to the current perl.exe I get:
Parent's name is [explorer.exe] Press ENTER to close the window:
Weirdly (well nothing is normal on this OS) the first time I got that the program was called by OpenWith.exe but once perl.exe is in the cached list of Open With.. the caller became explorer.exe which I suppose is the same if you double click it and you have its extension associated to perl.exe
L*
In reply to Re: Handling MSWin Script Output -- ParentPID
by Discipulus
in thread Handling MSWin Script Output
by kcott
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |