Why in perl system(" ") command, "source command_file" does nothing,but "source command_file && echo

Discussion in 'Perl Misc' started by Kuhl, Dec 22, 2008.

  1. Kuhl

    Kuhl Guest

    Hi, in my Perl script,

    system("source command_file");
    does nothing.

    But
    system("source command_file && echo");
    works correctly.

    How come?

    BTW, the command_file looks like below:

    calibre -query << ! | tee log_file
    filter layers lay_bond_pad
    net shapes AGNDP
    filter layers lay_bond_pad
    net shapes DM
    filter layers lay_bond_pad
    net shapes DP
    filter layers lay_bond_pad
    net shapes VDD
    !

    This is using the soft ware Calibre Query Server of Mentor Graphics.

    Thank you in advance.
    Kuhl, Dec 22, 2008
    #1
    1. Advertising

  2. Re: Why in perl system(" ") command, "source command_file" does nothing, but "source command_file && echo" works?

    Kuhl <> wrote:
    > Hi, in my Perl script,
    >
    > system("source command_file");
    > does nothing.



    You should always enable warnings when developing Perl code.


    > But
    > system("source command_file && echo");
    > works correctly.
    >
    > How come?



    Because "source" is a shell built-in and the 1st call does not
    invoke a shell (because it is a single arg with no shell metachars).

    perldoc -f system


    Either give system() a list of args that calls the shell you want:

    system("/bin/sh", "-c", "source command_file");

    or give system() a single arg that contains a shell metachar:

    system("source command_file;");


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Dec 22, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leszek Dubiel
    Replies:
    3
    Views:
    9,779
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,756
    Smokey Grindel
    Dec 2, 2006
  3. jobs
    Replies:
    1
    Views:
    456
  4. Brock Rycenga

    Rake "sh" does not echo command

    Brock Rycenga, Oct 22, 2008, in forum: Ruby
    Replies:
    2
    Views:
    108
    Brock Rycenga
    Oct 22, 2008
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    428
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page