0

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="
2
  • I want to avoid adding another escape character to the arguments given to the MonitorAdmin script. Commented Dec 9, 2011 at 4:20
  • 1
    Show us your buggy code so we can fix it. Commented Dec 9, 2011 at 6:52

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

There are 3 layers involved here, first call goes to MonitorAdmin perl script which executes another perl script like this: system "bash" , "-fc", "2ndPerlScript @ARGV" and then this 2nd perl script accumulate the user argument with the help of getoptions and propagates them to a shell script like this : system "bash", "-fc", "ShellScriptName $ARGUMENT_LIST"
But the problem is that when I pass on the @ARGV list in subsequent calls, the escape characters gets evaluated.
1

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.

2 Comments

Yes this appears to solve the problem about the special characters but now facing another problem viz. I want to pass few more arguments to the MonitorAdmin command along with @ARGV list. How would I do that in this form of 'system' command?
@Yogesh, It doesn't have to be an array, much less @ARGV. Just build an expression that returns the appropriate list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.