Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://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":



  • 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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2024-04-18 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found