Update: Ok, so can't use a BEGIN block...

On Windows, exec is simulated in a strange way. Apparently, it's creating a new process and exiting the caller before the new process exits.

(Update 2: On Linux, exec does not start a new process, it loads a new executable into the calling process. From the command shell's point of view, the process it launched is still running, so it's not trying to read STDIN.)

Your problem with system is that you need to exit after system returns:

use warnings; use strict; use Module::Load; if(! $ENV{SPRING_WRITEDIR}) { $ENV{SPRING_WRITEDIR}='E:\\test'; system {$^X} ($^X,$0); exit; }

Yes, you will have 2 Perl processes where you had 1, but one of those will be idle while waiting on the other to exit.

Please try:

use warnings; use strict; BEGIN { $ENV{SPRING_WRITEDIR}='E:\\test'; $ENV{PATH}="E:\\springrts;$ENV{PATH}"; } use Module::Load; load("PerlUnitSync"); PerlUnitSync::Init(0,0); my $writeDir=PerlUnitSync::GetWritableDataDirectory(); print "writeDir=$writeDir\n";

This will set the environment before Module::Load is loaded.


In reply to Re^17: Using STDIN after exec() with ActiveState Perl by RonW
in thread Using STDIN after exec() with ActiveState Perl by Yaribz

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.