Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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


In reply to Win32 backticks fail when too many ENV vars by jimbojones

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (13)
    As of 2014-10-24 17:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (134 votes), past polls