[pgh-pm] system() not displaying scalar text
Tom Moertel
tom at moertel.com
Tue Sep 4 14:37:17 PDT 2007
Matthew T. Engel wrote:
> [...] However, if I do a $ cat
> unicode_text_file | ./above_script.pl. I get blank lines where the
> echo’d data should be.
>
> I think the second file is Unicode because doing a $od –c Unicode_text
> file, shows /0 in front of all the characters, and if I vi the same file
> it shows ^@ before every character.
That's your problem.
Under the hood, arguments are passed to programs as traditional C-style,
null-terminated strings. (For more, read man page for the exec(3)
system call: "const char *arg: a list of one or more pointers to
null-terminated strings that represent the argument list available to
the executed program.") Therefore, when you pass an argument that
contains a 0 byte to Perl's "system" function, the program that Perl
invokes will see only the portion of the argument up to the 0, but
nothing more. For example:
$ perl -e 'system "echo hi"'
hi
$ perl -e 'system "echo \0hi"'
$
Cheers,
Tom
More information about the pgh-pm
mailing list