[tpm] How to pipe variable content to shell scripts

Shlomi Fish shlomif at shlomifish.org
Tue Jan 21 10:42:28 PST 2014


Hi Antonio,

On Tue, 21 Jan 2014 12:29:43 -0500
Antonio Sun <tpm.ats at spamgourmet.com> wrote:

> Hi,
> 
> I have a script that works on xml content. A thousand time simplified
> version is:
> 
>  xml_output | perl -n000e 's,(?<=">)(.*?)(?=</HttpBody>),`echo $1 | wc
> -c`,eg; print'
> 

why are you doing `echo $1 | wc -c` instead of simply doing «length($1)»?
Also see http://perl-begin.org/topics/security/code-markup-injection/ and
http://perl-begin.org/tutorials/bad-elements/#calling-the-shell-too-much .

> I.e., I need to pipe the matching string ($1, content between tag HttpBody)
> to an external program via shell. As you can tell, if the matching content is
> too big for shell parameter length, my script will fail.
> 
> I *have to* process the matching string via the external program. Is there
> any way I can get around this?

If you need to do so use https://metacpan.org/pod/IPC::Run or
https://metacpan.org/pod/String::ShellQuote or
https://metacpan.org/pod/IPC::System::Simple .

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang

Chuck Norris has actually been using Perl 6 since 1987, and has been waiting
for Larry to play catch‐up.
    — dukeleto ; http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

Please reply to list if it's a mailing list post - http://shlom.in/reply .


More information about the toronto-pm mailing list