Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Problem using Backtick having quotes

by fizbin (Chaplain)
on Oct 19, 2005 at 13:14 UTC ( [id://501290]=note: print w/replies, xml ) Need Help??


in reply to Problem using Backtick having quotes

The only thing I can think is that when you have quote marks the string as a whole contains "shell metacharacters", and when you don't, it doesn't.

For example, see this bit from the documentation for perl's system command:

If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is "/bin/sh -c" on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to "execvp", which is more efficient.
So, for some reason, invoking "/bin/sh -c" is clearing the environment before running the command. I find this a bit odd, but you can check it with this simple perl script:
#!perl $ENV{CLASSPATH}="/usr/work/ticket/ETicketClient.jar:."; print "Without shell metachars we get:\n", grep(/CLASSPATH/, qx[/usr/bin/env]), "\n"; print "With shell metachars we get:\n", grep(/CLASSPATH/, qx[/bin/false || /usr/bin/env]), "\n";

See if there's a difference in the two outputs.

So then, the question is, why is this clearing the environment? It's not supposed to, but I wonder if on your system /bin/sh is aliased to csh. (or if perhaps the qx[] operator uses your default shell, which might be csh) Csh has a habit of always running its initialization scripts even if it's just being called for one command, and that could reset your environment variable settings.

Fortunately, for java there is a simple solution - you can change your original code to:

#!/usr/bin/perl -w my $cp = "/usr/work/ticket/ETicketClient.jar:."; $ENV{PATH}.=":/usr/work/ticket/" $test="This is perl ticket"; my $result =qx/java -cp \Q$cp\E ETicket.ETicketClient -i TICKET -n p_ +name -t "\Q$test\E"/; print $result;
That is, use the -cp argument to set the classpath for java even when the environment is being reset.
--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://501290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-19 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found