Operating System - HP-UX
1825808 Members
2223 Online
109688 Solutions
New Discussion

Re: Command Substitution is not working

 
vinodan
Advisor

Command Substitution is not working

When I am calling a command from a perl script via command ticks i.e ` then if my command has a | it fails
eg.
=`ls | wc -l` doesn't give me any output in the variable
but =`ls` works

The same works on other servers. Perl instalation, version, modules etc is all the same. | works on command prompt but not via programs

$ uname -a
HP-UX Server_Name B.11.11 U 9000/800 1849201262 unlimited-user license

$ perl -v

This is perl, v5.8.7 built for PA-RISC2.0-thread-multi
6 REPLIES 6
Muthukumar_5
Honored Contributor

Re: Command Substitution is not working

Can you try like this,

perl -e '$var=`ls | wc -l`;print $var;'

It has to work.

-Muthu
Easy to suggest when don't know about the problem!
vinodan
Advisor

Re: Command Substitution is not working

Hi,
It doesn't work

testsw /home/testsw>perl -e '$var=`ls | wc -l`;print $var;'
testsw /home/testsw>

but

testsw /home/testsw>perl -e '$var=`ls`;print $var;'
a.pl
data
ftpdtls.txt
ftpuploaddtls.txt
getPatchInfo
getclientdetails.pl
maintainhash
maintainhashcron.sh
nohup.out
setdistenv
testing.sh
testsw /home/testsw>


So i'm back to where I was, the | doesn't work from perl
Muthukumar_5
Honored Contributor

Re: Command Substitution is not working

Try this:

# perl -We '$var=`ls | wc -l`;print $var;'
# perl -We '$var=qx[ls | wc -l];print $var;'

--
Muthu
Easy to suggest when don't know about the problem!
Oviwan
Honored Contributor

Re: Command Substitution is not working

Hi

what is with the other pipe-operators (<,>,|)?
does this works?

#perl -e '`ls > list`;'
#cat list

Regards
Andrew Merritt_2
Honored Contributor

Re: Command Substitution is not working

So this is a problem on only one system, is that right?

Perhaps it's not a problem with perl, but with the environment you're running it in. What shell are you running on the system that doesn't work, and what on the systems that do?

What is the output of 'stty -a' on the non-working and working systems?

What happens if you put the line in a file, and run that (e.g. put the line in a file and run the file with 'sh /tmp/filename' or even 'sh -x /tmp/filename')?

Andrew
TwoProc
Honored Contributor

Re: Command Substitution is not working

As I was reading this, I began to suspect where Andrew went with it, that is, maybe you've got the "|" redefined in your stty settings.

run "stty -a" and see if you see a "|" symbol in there.
We are the people our parents warned us about --Jimmy Buffett