command output

Discussion in 'Perl Misc' started by jammer, Mar 13, 2008.

  1. jammer

    jammer Guest

    There is no output from this:
    `/usr/bin/ls -l "$backupDir/$backupName"`;

    This shows correct values:
    print "/usr/bin/ls -l $backupDir/$backupName";
     
    jammer, Mar 13, 2008
    #1
    1. Advertising

  2. jammer

    J. Gleixner Guest

    jammer wrote:
    > There is no output from this:
    > `/usr/bin/ls -l "$backupDir/$backupName"`;
    >
    > This shows correct values:
    > print "/usr/bin/ls -l $backupDir/$backupName";


    Correct values??? It prints:

    /usr/bin/ls -l /

    It sounds like you answered your own question though, whatever
    that question was.

    Possibly this is what you're after:

    perldoc -q "Why can't I get the output of a command with system"
     
    J. Gleixner, Mar 13, 2008
    #2
    1. Advertising

  3. jammer wrote:
    > There is no output from this:
    > `/usr/bin/ls -l "$backupDir/$backupName"`;


    Are you sure that the ls program resides in /usr/bin? On my box it's
    located in /bin, but in any case

    `ls -l "$backupDir/$backupName"`

    ought to be sufficient.

    Otherwise, if you for some reason don't see what is in STDERR, you may
    want to try:

    `/usr/bin/ls -l "$backupDir/$backupName" 2>&1`

    Please see http://perldoc.perl.org/perlop.html#qx/STRING/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 13, 2008
    #3
  4. jammer

    Paul Lalli Guest

    On Mar 13, 2:01 pm, jammer <> wrote:
    > There is no output from this:
    >                 `/usr/bin/ls -l "$backupDir/$backupName"`;


    Why would there be? You're capturing the output and then discarding
    it by using `` in a void context.

    Read perldoc perlop (search for qx//) to learn what `` actually do,
    because you don't seem to understand them.

    Paul Lalli
     
    Paul Lalli, Mar 13, 2008
    #4
  5. jammer <> wrote:
    >There is no output from this:
    > `/usr/bin/ls -l "$backupDir/$backupName"`;


    Does that surprise you? It shouldn't.

    >This shows correct values:
    > print "/usr/bin/ls -l $backupDir/$backupName";


    Whatever "correct values" is supposed to mean. It will print that given
    string with the two variables $backupDir and $backupName expanded. Did you
    expect something else?

    Of course backticks to do something different then double quotes. Does that
    surprise you?

    What is your question/issue/...?

    jue
     
    Jürgen Exner, Mar 13, 2008
    #5
  6. jammer <> wrote:
    > There is no output from this:
    > `/usr/bin/ls -l "$backupDir/$backupName"`;



    That is because there are no output statements there.


    > This shows correct values:
    > print "/usr/bin/ls -l $backupDir/$backupName";



    That's nice.

    Did you mean to ask a question?


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 13, 2008
    #6
  7. "jammer" <> wrote in message
    news:...
    > There is no output from this:
    > `/usr/bin/ls -l "$backupDir/$backupName"`;
    >
    > This shows correct values:
    > print "/usr/bin/ls -l $backupDir/$backupName";


    Assuming you provide the complete lines:

    In the first line, you gather data via the backticks, but you
    don't do anything with the returned data. It's like having
    a line like these:

    "blah";
    1;

    You need to do something with the data; e.g., print it:

    print `/usr/bin/ls -l "$backupDir/$backupName"`;

    In the second line, you are printing the command itself and
    not executing it.

    Mario
     
    Mario D'Alessio, Mar 14, 2008
    #7
  8. jammer

    jammer Guest

    On Mar 13, 4:09 pm, Jürgen Exner <> wrote:
    > jammer <> wrote:
    > >There is no output from this:
    > > `/usr/bin/ls -l "$backupDir/$backupName"`;

    >
    > Does that surprise you? It shouldn't.
    >
    > >This shows correct values:
    > > print "/usr/bin/ls -l $backupDir/$backupName";

    >
    > Whatever "correct values" is supposed to mean. It will print that given
    > string with the two variables $backupDir and $backupName expanded. Did you
    > expect something else?
    >
    > Of course backticks to do something different then double quotes. Does that
    > surprise you?
    >
    > What is your question/issue/...?
    >
    > jue


    Printing $backupDir and $backupName show they are not empty.
    I wanted to print the output of the ls -l.
    I know how to do it now.
     
    jammer, Mar 14, 2008
    #8
  9. jammer

    jammer Guest

    On Mar 14, 9:59 am, jammer <> wrote:
    > On Mar 13, 4:09 pm, Jürgen Exner <> wrote:
    >
    >
    >
    > > jammer <> wrote:
    > > >There is no output from this:
    > > > `/usr/bin/ls -l "$backupDir/$backupName"`;

    >
    > > Does that surprise you? It shouldn't.

    >
    > > >This shows correct values:
    > > > print "/usr/bin/ls -l $backupDir/$backupName";

    >
    > > Whatever "correct values" is supposed to mean. It will print that given
    > > string with the two variables $backupDir and $backupName expanded. Did you
    > > expect something else?

    >
    > > Of course backticks to do something different then double quotes. Does that
    > > surprise you?

    >
    > > What is your question/issue/...?

    >
    > > jue

    >
    > Printing $backupDir and $backupName show they are not empty.
    > I wanted to print the output of the ls -l.
    > I know how to do it now.


    I did print `/usr/bin/ls -l "$backupDir/$backupName"`;
    It is truncating and printing the last character:
    -rw-r--r-- 1 owner group 3858 Mar 14 10:47 /tmp/configs/
    file.cog
    It should print:
    -rw-r--r-- 1 owner group 3858 Mar 14 10:47 /tmp/configs/
    file.config
     
    jammer, Mar 14, 2008
    #9
  10. jammer

    jammer Guest

    On Mar 14, 10:56 am, jammer <> wrote:
    > On Mar 14, 9:59 am, jammer <> wrote:
    >
    >
    >
    > > On Mar 13, 4:09 pm, Jürgen Exner <> wrote:

    >
    > > > jammer <> wrote:
    > > > >There is no output from this:
    > > > > `/usr/bin/ls -l "$backupDir/$backupName"`;

    >
    > > > Does that surprise you? It shouldn't.

    >
    > > > >This shows correct values:
    > > > > print "/usr/bin/ls -l $backupDir/$backupName";

    >
    > > > Whatever "correct values" is supposed to mean. It will print that given
    > > > string with the two variables $backupDir and $backupName expanded. Didyou
    > > > expect something else?

    >
    > > > Of course backticks to do something different then double quotes. Doesthat
    > > > surprise you?

    >
    > > > What is your question/issue/...?

    >
    > > > jue

    >
    > > Printing $backupDir and $backupName show they are not empty.
    > > I wanted to print the output of the ls -l.
    > > I know how to do it now.

    >
    > I did print `/usr/bin/ls -l "$backupDir/$backupName"`;
    > It is truncating and printing the last character:
    > -rw-r--r-- 1 owner group 3858 Mar 14 10:47 /tmp/configs/
    > file.cog
    > It should print:
    > -rw-r--r-- 1 owner group 3858 Mar 14 10:47 /tmp/configs/
    > file.config


    It was my TERM truncating it, not Perl, no problem.
     
    jammer, Mar 14, 2008
    #10
    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:
    548
    San Diego Guy
    Aug 7, 2003
  2. Lucas Cowald
    Replies:
    4
    Views:
    1,071
    Tohid
    Oct 23, 2003
  3. Bernd Oninger
    Replies:
    1
    Views:
    792
    Martin Honnen
    Jul 7, 2004
  4. Christian Seberino
    Replies:
    0
    Views:
    479
    Christian Seberino
    Oct 21, 2003
  5. Replies:
    4
    Views:
    1,715
    Terry Hancock
    Apr 23, 2005
Loading...

Share This Page