Hi
I need help with executing a child process on windows. I've found that if the number of ENV variables are too big, Perl will not create the child cmd.exe process.
use warnings;
use strict;
my $max = 69; #-- tweak this to get it to fail
foreach my $i ( 1 .. $max )
{
my $t = "ENV$i";
my $m = max( $i, 20);
$ENV{$t} = "big string" x $m;
}
my @env = keys %ENV;
print "# of ENV: ", scalar keys %ENV, "\n";
#-- calculate the lenght of the env list
my $env_str = '';
foreach my $key ( keys %ENV )
{
$env_str .= "$key=" . $ENV{$key} . " "; #-- space represents \0 inter
+nal in pointer
}
print "Length ENV str: ", (length( $env_str) + 1), "\n";
print `set`;
print "RC: ", $?, "\n";
#------------------------------------------------------------------
sub max
{
my ( $i, $j ) = @_;
if ( $i > $j )
{
return $i;
}
return $j;
}
You may have to tweak
$max to get it to fail depending on how many ENV variables are predefined on your system.
It fails like this:
# of ENV: 127
Length ENV str: 30798
RC: -1
.. but I think it's the length of the string, not the number of ENV variables, that affects whether it fails. E.g, change the max on the "big string" to 40 from 20, and it fails at 118 env variables and a length of 30785.
I looked in the source code and it indicates that the cmd process is created with
CreateProcess that passes in
(LPVOID)env, /* inherit environment */. I cannot find any limit on the
env string on the Microsoft site. Is there a magic number limit internal to perl?
Thanks in advance.
- j
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.