Yogesh
Yogesh

Reputation: 11

Calling perl script from a perl script

I want to call a perl script from a perl script with big argument list in a bash shell. The arguments contains special characters such as \, *, (, ) etc. Each of these special characters are guided by single escape character \.

But when I call 2nd perl script (which then calls to a shell script) from 1st perl script the escape character gets evaluated and the special characters are exposed in the shell and hence getting syntax error.

So basically i want to prevent escape character's evaluation when I call 2nd perl script from 1st perl script and it should be evaluated when I call shell script from my 2nd perl script.

Eg. Input to the first perl 'MonitorAdmin' script is :

MonitorAdmin -reversefilter -container="LogServerContainer" -filepath="/home/esg2/YogeshTemp/VSDEFAULT/logs" -filename="System.log" -pattern=".*\t.*\t(DEBUG)\t.*\t.*\t.*\t(SecurityService)\t.*\t.*\t.*\t.*\t.*" -linecount="5001" -targetfile="

Upvotes: 0

Views: 350

Answers (2)

ikegami
ikegami

Reputation: 385556

There are two forms of system, one that executes a shell command (system($shell_cmd)), and one that launches a program (system($program, @args)). As best as we can tell by your light post, you appear to be using the wrong one. All you need is

system('MonitorAdmin2', @ARGV)

There is no shell to "misinterpret" the characters.

Upvotes: 1

Jeff Burdges
Jeff Burdges

Reputation: 4251

Perl's exec and system commands won't invoke a shell if you pass them a list with more than one element, but each list element becomes a separate argument then, i.e. spaces don't separate arguments. I'd imagine this works well even when executing a shell script since you aren't invoking the shall with a -c option.

Upvotes: 2

Related Questions