The way to get a get a tty attached to the remote process is to pass tty => 1 when calling Net::OpenSSH methods. For instance:
my $file_list = $ssh->capture({tty => 1}, "ls -l");
In any case, interacting with sudo is almost an art. There are too many different versions with different capabilities still in use, and then, there were several (minor) bugs related to tty handling on OpenSSH client that have been fixed only on recent releases.

In the end, the only approach that is guaranteed to works in all the cases is using Expect, because you have a tty in both sides (ssh handles that without issues) and you are not using new and fancy sudo features. The downside is that using Expect is a PITA.

In summary, read the documentation for the version of sudo installed on the remote machine. Check if all the flags used by the sample code are available. Try doing it from the command line. Also, try asking Net::OpenSSH/ssh to allocate a tty on the remote side. If everything fails, go for Expect (but combined with Net::OpenSSH as explained in the docs, don't use Net::SSH::Expect that is quite buggy!).

Net::OpenSSH also has a debugging mode that could give you some hint about what is going wrong:

$Net::OpenSSH::debug = -1;

In reply to Re: Sudo with Net::OpenSSH fails with PROCESS_MUX_NEW_SESSION: tcgetattr: Inappropriate ioctl for device by salva
in thread Sudo with Net::OpenSSH fails with PROCESS_MUX_NEW_SESSION: tcgetattr: Inappropriate ioctl for device by jester47

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.