Hello kcott,

> 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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Handling MSWin Script Output -- ParentPID by Discipulus
in thread Handling MSWin Script Output by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.