Re: qx() won't accept over (about) 128,000 characters
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 15 May 2007 09:36:12 -0700
Jameson C. Burt wrote:
Within Perl, I construct programs in other programming languages
and submit the result to a Unix (Linux or IBM AIX) operating system
with 2GB to 8GB memory.
I submit such a program to the operating system using Perl's
qx()
Unfortunately, giving qx() over 128,420 characters (about and can vary
by a few characters) then returns nothing.
Yet, giving qx() 128,000 characters gets properly executed by the
operating system.
Following is an example,
expedited from my original test that actually had 1270 lines.
Only with fewer lines (eg, replace 1370 by 1269) will this program output
"Last line of large program!"
Here's the program that constructs
and tries giving qx() over 128,000 characters of code:
#!/usr/bin/perl -w
$shorty = ' ' x 99 . '#' . "\n" ; #100/101 characters
#Repeat 1370 lines of $shorty into @manylines:
# foreach $i (0..1269) {$manylines[$i] = $shorty} ; #Succeeds
foreach $i (0..1370) {$manylines[$i] = $shorty} ;
$manylines[$#manylines + 1] = 'echo "Last Line of large program!"' ;
You can simplify that to:
my @manylines = ( ( ' ' x 99 . "#\n" ) x 1371, 'echo "Last Line of large
program!"' );
print qx(@manylines) ;
# system(qq(@manylines)) ; #Same problem.
Your line of code is a comment (The # character starts a comment in shell)
which is why nothing is returned:
$ perl -e'
my @manylines = ( ( " " x 99 . "#\n" ) x 1371, q[echo "Last Line of large
program!"] );
print qx[@manylines];
' | wc
0 0 0
$ perl -e'
my @manylines = ( ( " " x 99 . "\n" ) x 1371, q[echo "Last Line of large
program!"] );
print qx[@manylines];
' | wc
1 5 28
$ perl -e'
my @manylines = ( ( " " x 99 . "\n" ) x 1371, q[echo "Last Line of large
program!"] );
print qx[@manylines];
'
Last Line of large program!
However, appending the following lines to the above code
will properly execute those 1370 lines.
open(OUTFILE, ">/tmp/zz.out") ;
print(OUTFILE @manylines) ;
close(OUTFILE) ;
system("bash /tmp/zz.out") ;
While I can run this latter code, it both adds more code
and adds a file to the operating system's filesystem.
Can qx() accept large numbers of characters,
perhaps using some simple technique?
When it is saved as a file the shell (bash) ignores the comment lines.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- Follow-Ups:
- Re: qx() won't accept over (about) 128,000 characters
- From: Jameson C. Burt
- Re: qx() won't accept over (about) 128,000 characters
- References:
- qx() won't accept over (about) 128,000 characters
- From: Jameson C. Burt
- qx() won't accept over (about) 128,000 characters
- Prev by Date: How to specify a file spec on the command line
- Next by Date: Assign a delimiter variable
- Previous by thread: qx() won't accept over (about) 128,000 characters
- Next by thread: Re: qx() won't accept over (about) 128,000 characters
- Index(es):
Relevant Pages
|