Im sure this is an easy question, but since im a perl n00b, here it goes

I need to run an executable to my Ubuntu Linux box, get the status of something then use that status to fill out and if/else statement

This is what I have right now

my $enable_poe = `poe ds`; if ($enable_poe eq 'POE device missing or unpowered') { print $enable_poe, "\n", "Your Poe IS NOT enabled, dummy\n"; } elsif($enable_poe eq 'Device ID 2, Rev. 0') { print $enable_poe, "\n", "Your PoE IS enabled, dummy\n"; } else { print "\nnothing happened\n"; }

when I run poe ds on the terminal it will either return

user@device:/tmp$ poe ds Device ID 2, Rev. 0

if the port is active or

POE device missing or unpowered

if the device is missing

Whats happening is the print statement to return the value of $enable_poe is working, but the if/else conditions are not

In this case, if the poe ds command recognizes the unit and returns

Device ID 2, Rev. 0

But the output of the script reads

Device ID 2, Rev. 0 Your Poe IS NOT enabled, dummy

so its returning the first print statement and not reading the

if ($enable_poe == 'POE device missing or unpowered')

line

What am I doing incorrect here? I want the poe ds command to be read, then use what it returns in that if/else statement

Code tags added by GrandFather


In reply to Returning a string from executable by Luken8r

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.