system command question

Discussion in 'Perl Misc' started by Himal, Sep 10, 2003.

  1. Himal

    Himal Guest

    I there a reason why a command will not work if i do system "$cmd &>
    xyz.log" even though it works if I do system "$cmd"
     
    Himal, Sep 10, 2003
    #1
    1. Advertising

  2. Himal

    J. Gleixner Guest

    Himal wrote:
    > I there a reason why a command will not work if i do system "$cmd &>
    > xyz.log" even though it works if I do system "$cmd"


    This is an OS/Shell issue.

    From your command line try:

    whateverCommandYouAreTryingToRun & > xyz.log

    and you should see the error.
     
    J. Gleixner, Sep 10, 2003
    #2
    1. Advertising

  3. Himal wrote:
    > I there a reason why a command will not work if i do system "$cmd &>
    > xyz.log" even though it works if I do system "$cmd"


    Most likely, the shell perl is using to parse your command is
    not csh. Exactly why this is so would depend on your configuration.
    Try this, which will work for sh/ksh/bash: system "$cmd >xyz.log 2>&1"

    Chris Mattern
     
    Chris Mattern, Sep 12, 2003
    #3
  4. In article <>, Chris Mattern wrote:
    > Himal wrote:
    >> I there a reason why a command will not work if i do system "$cmd &>
    >> xyz.log" even though it works if I do system "$cmd"

    >
    > Most likely, the shell perl is using to parse your command is
    > not csh. Exactly why this is so would depend on your configuration.
    > Try this, which will work for sh/ksh/bash: system "$cmd >xyz.log 2>&1"


    There is no reason for it to be csh. The manual for the system
    command says:

    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 it's either /bin/sh (on Unix systems) or no shell at all.,
    if you haven't done some pretty freakish changes in the default
    configuration.

    --
    Andreas Kähäri
     
    Andreas Kahari, Sep 12, 2003
    #4
  5. Andreas Kahari wrote:
    > In article <>, Chris Mattern wrote:
    >
    >>Himal wrote:
    >>
    >>>I there a reason why a command will not work if i do system "$cmd &>
    >>>xyz.log" even though it works if I do system "$cmd"

    >>
    >>Most likely, the shell perl is using to parse your command is
    >>not csh. Exactly why this is so would depend on your configuration.
    >>Try this, which will work for sh/ksh/bash: system "$cmd >xyz.log 2>&1"

    >
    >
    > There is no reason for it to be csh. The manual for the system
    > command says:
    >
    > 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 it's either /bin/sh (on Unix systems) or no shell at all.,
    > if you haven't done some pretty freakish changes in the default
    > configuration.
    >


    Ah, OK, I thought it used the user's shell. OK, then,
    system "$cmd >xyz.log 2>&1" should be the answer, assuming
    the OP is on a Unix system (which seems logical, since he's
    trying to use csh syntax).

    Chris Mattern
     
    Chris Mattern, Sep 12, 2003
    #5
  6. Himal

    Anno Siegel Guest

    Chris Mattern <> wrote in comp.lang.perl.misc:
    > Andreas Kahari wrote:
    > > In article <>, Chris Mattern wrote:
    > >
    > >>Himal wrote:
    > >>
    > >>>I there a reason why a command will not work if i do system "$cmd &>
    > >>>xyz.log" even though it works if I do system "$cmd"


    [...]

    > Ah, OK, I thought it used the user's shell. OK, then,
    > system "$cmd >xyz.log 2>&1" should be the answer, assuming
    > the OP is on a Unix system (which seems logical, since he's
    > trying to use csh syntax).


    Except that he isn't. "$cmd >& xyz.log" would be csh syntax.
    "$cmd &> xyz.log" is neither here nor there.

    Anno
     
    Anno Siegel, Sep 15, 2003
    #6
  7. Himal

    none Guest

    In article <bk4l5q$1uv$-Berlin.DE>,
    Anno Siegel <-berlin.de> wrote:
    >> Ah, OK, I thought it used the user's shell. OK, then,
    >> system "$cmd >xyz.log 2>&1" should be the answer, assuming
    >> the OP is on a Unix system (which seems logical, since he's
    >> trying to use csh syntax).

    >
    >Except that he isn't. "$cmd >& xyz.log" would be csh syntax.
    >"$cmd &> xyz.log" is neither here nor there.


    It's zsh syntax.

    Ben
    --
    And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
    * *
     
    none, Oct 26, 2003
    #7
  8. Can you not precede the entire command with /usr/bin/csh if you want to
    execute it under the csh? For example, system("csh $cmd >& xyz.log");

    Rod


    none wrote:

    >In article <bk4l5q$1uv$-Berlin.DE>,
    >Anno Siegel <-berlin.de> wrote:
    >
    >
    >>>Ah, OK, I thought it used the user's shell. OK, then,
    >>>system "$cmd >xyz.log 2>&1" should be the answer, assuming
    >>>the OP is on a Unix system (which seems logical, since he's
    >>>trying to use csh syntax).
    >>>
    >>>

    >>Except that he isn't. "$cmd >& xyz.log" would be csh syntax.
    >>"$cmd &> xyz.log" is neither here nor there.
    >>
    >>

    >
    >It's zsh syntax.
    >
    >Ben
    >
    >
     
    Roderick Allen, Oct 27, 2003
    #8
    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. San Diego Guy
    Replies:
    0
    Views:
    563
    San Diego Guy
    Aug 7, 2003
  2. Lucas Cowald
    Replies:
    4
    Views:
    1,105
    Tohid
    Oct 23, 2003
  3. Bernd Oninger
    Replies:
    1
    Views:
    820
    Martin Honnen
    Jul 7, 2004
  4. Irmen de Jong
    Replies:
    2
    Views:
    440
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Aug 12, 2003
  5. boriq
    Replies:
    4
    Views:
    598
    Tim Golden
    Jun 12, 2008
Loading...

Share This Page