Loading ...
Sorry, an error occurred while loading the content.

Perl backtick to capture cmd output

Expand Messages
  • Tim Lewis
    I am using the backtick operator to capture output. However, I need to pass a scalar variable into the backtick section, instead of a literal command. Is that
    Message 1 of 3 , Jan 4, 2011
    View Source
    • 0 Attachment
      I am using the backtick operator to capture output. However, I need to pass
      a scalar variable into the backtick section, instead of a literal command.
      Is that possible?

      For example,

      $myOutput = `dir`;

      print "Output is $myOutput\n";



      Is there a way to do this:

      $myCommand = "dir";

      $myOutput = '$myCommand';

      Print "Output is $myOutput\n";



      The above code does not work as I wish. It prints the literal "dir".

      Thanks for any help.

      Tim







      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Tim $myOutput = $myCommand ; Wrong quotes. You want `` not . -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      Message 2 of 3 , Jan 4, 2011
      View Source
      • 0 Attachment
        >>>>> "Tim" == Tim Lewis <twlewis@...> writes:

        Tim> $myOutput = '$myCommand';

        Wrong quotes. You want `` not ''.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.posterous.com/ for Smalltalk discussion
      • Tim Lewis
        Thanks Randal. I should have caught that. It is always the simple things that bite the worst. From: perl-beginner@yahoogroups.com
        Message 3 of 3 , Jan 4, 2011
        View Source
        • 0 Attachment
          Thanks Randal. I should have caught that. It is always the simple things
          that bite the worst.



          From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
          On Behalf Of merlyn@...
          Sent: Tuesday, January 04, 2011 12:55 PM
          To: Tim Lewis
          Cc: perl-beginner@yahoogroups.com
          Subject: Re: [PBML] Perl backtick to capture cmd output





          >>>>> "Tim" == Tim Lewis <twlewis@... <mailto:twlewis%40sc.rr.com> >
          writes:

          Tim> $myOutput = '$myCommand';

          Wrong quotes. You want `` not ''.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@... <mailto:merlyn%40stonehenge.com> >
          <URL:http://www.stonehenge.com/merlyn/>
          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          See http://methodsandmessages.posterous.com/ for Smalltalk discussion





          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.