Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Query on Perl system command

by philipbailey (Chaplain)
on Mar 04, 2011 at 12:48 UTC ( #891441=note: print w/replies, xml ) Need Help??


in reply to Query on Perl system command

It looks like a quoting problem. It seems that you want to interpolate your variable $filename within your quoted string but interpolation does not happen within Perl's single quotes.

There are several possibilities, but one would be to use double quotes, then escape the double quotes and "\n" you are using:

system "echo -e \"$filename.txt\\n$filename.xls\\n\" | phylip";

Also note that, on my system at least, I need the -e option to get backslash escapes to be interpreted.

Replies are listed 'Best First'.
Re^2: Query on Perl system command
by Anonymous Monk on Mar 04, 2011 at 14:22 UTC

    Thanks Philip Bailey.

    I put up a simplified script in my query, but the actual script is different. It is given below. (Description of this script is in Re^4 above)

    As suggested by you, I modified script

    system 'echo "4\n6\n3\n5\n\n1\n$filename.fsmi\n5\n$filename.phb\n111\n +1000\n4\n$filename.ph\n$filename.dst\n\n2\n" | phylip';

    with

    system "echo -e \"4\\n6\\n3\\n5\\n\\n1\\n\"$filename.fsmi\"\\n5\\n\"$f +ilename.phb\"\\n111\\n1000\\n4\\n\"$filename.ph\"\\n\"$filename.dst\" +\\n\\nx\\n\" | phylip" ;

    I did not get any error message, but, none of the choices are recognized

    I appreciate your help, thank you

      Have you also tried without the -e option?  Not all echos require that option, and in the other thread it looks like your echo doesn't.

      Another approach would be to do away with system, echo, quoting issues, etc. and use open to open a pipe to phylip, into which you then just print the required input, including newlines.  For example:

      open my $pipe, "| phylip" or die $!; print $pipe <<"EOI"; 4 6 3 5 1 $filename.fsmi 5 $filename.phb 111 1000 4 $filename.ph $filename.dst x EOI close $pipe;

      A positive side effect is that the sequence of things you have to enter becomes much better to read.

      (Note that the heredoc, as shown, is interpolating $filename (like a double-quoted string). )

        Thank you Eliya :-)

        Yes, you are right, open command is much easier to read and it works perfectly well.

        Chak

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://891441]
help
Chatterbox?
[Marshall]: Darn! I'll look at the thread. Must not be updatinga byte count somewhere. The .exe format is a complex critter.
[stevieb]: that way, it's still "hard coded" into the exe at least, despite not being visible via Properties
[Marshall]: I also looked into PerlApp from Active State, but they don't sell their Dev Kit independent of a very expensive ($1,200) per year license anymore.
[Corion]: I would assume that the PE format hasn't changed that much since the days of yore, but it seems that I would be wrong in that assumption
[Marshall]: When I bought my copy 15+ years ago, it was just a couple hundred bucks.
[Marshall]: I looked at MS specs for PE format and I didn't see any changes in last decade, but evidenly that would be wrong.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2016-12-08 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (144 votes). Check out past polls.