Windows7 won't change anything :)

What you have here, is cmd being cmd, the cmd way , and perl being perl

cmd.exe is a special kind of program

Instead of striking out the incorrect parts of my investigation below, everything is in readmore

Read $ help call

Install procexp.exe from http://live.sysinternals.com/ and start it from your experiment shell, and then watch the tree of processes after each action (like Ctrl+C)

After launching the batch file, i see the cmd that launched the batch, its child, a perl process, with a child of cmd.exe

On 1st ctrl+C, the perl process ends, as does the cmd.exe process, they're both gone from procexp/taskmanager

But cmd being so special, you have to exit really end the subshell , its the only way

The perl process has ended, the cmd it launched is still around, but it is nobodys child

When you launch a cmd from a cmd from a cmd, each subsequent cmd is a child of the former, and Ctrl+C doesn't kill it, or make it an orphan

You'll notice, when you hit ctrl+c, you get double newlines, thats because, apparently, ctrl+c is being propagated to both cmds

You'll also notice at first it won't take your y/n, but if you try it a second time, it will

Terminating on signal SIGINT(2) $ Terminate batch job (Y/N)? y 'y' is not recognized as an internal or external command, operable program or batch file. $ y $ exit
See, the thing is, all 3 things share the same STDIN/STDERR/STDOUT among other things

See DLL_PROCESS_ATTACH

I don't have a complete grasp of everything, but yes, there is a bug in there somewhere, probably in the perl dll hook, not detaching cleanly, maybe

You might also be able to glean some leads from these frontends/wrappers for cmd.exe, eConsole and console2

On the other hand, perl on win32 has behaved this way for a long time (11+ years at least)

So I can't help but think, the porters, and ActiveState, left it this way for a reason -- either its unfixable, or its the best compromise available ...

What you want to do is use $SIG{INT}='IGNORE'; so that pressing Ctrl+C doesn't end the shell launched by perl, force the user to type exit, like
call perl -le " $SIG{INT}=q[IGNORE]; $ENV{X}='Y'; $ret = system('cmd') +; print qq[system returned $ret ]; "

But that still leaves the problem of being prompted by the original shell running the batch file

$ exit system returned 0 Terminate batch job (Y/N)? y
$ exit system returned 0 Terminate batch job (Y/N)? n finished

I'm not sure how to signal to it, that everything is ok , no need to prompt, the answer probably lies in that dllhook business :/


In reply to Re: Interaction of Windows Batch files and Perl's system() function by Anonymous Monk
in thread Interaction of Windows Batch files and Perl's system() function by rovf

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.