And, does someone know a better way to "restart myself"?
I would use $^X instead of $Config{perlpath}, since the perl executable might not be where it was configured for it to be. No need to "use Config" to get $^X.
However the behaviour I am experiencing, does not match this either. Instead, I get a CMD.EXE shell plus my Perl program in parallel! Any explanation for this?
If you want really interesting behavior, try this in the dummy code:
while(1) { sleep(5); my $x=scalar<>;print "running $$:$x\n"; }
Then you'll see that when that thread comes out of sleep, it grabs stdin. Otherwise, the CMD shell has it.

My guess is that the parent thread, started with the relative path, starts a new thread with the EXEC and then exits, giving control back to the shell. The child thread (started with an absolute path) inherited stdin & stdout, so its input & output are interleaved with the command window.

My suggestion is to not respawn. Just overwrite $0!

$0=rel2abs($0) unless file_name_is_absolute $0;
That is, "lie" to make it look like your script was started with an absolute path.

In reply to Re: exec on Windows "halfway forks" by Yary
in thread exec on Windows "halfway forks" 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.