Hello glasswalk3r,

Why not use Net::OpenSSH or Net::OpenSSH::Parallel where you can set on the options close_slave_pty => 0 and then close the slave your self like: $slave = $pty->slave; close($slave).

From Net::OpenSSH documentation:

close_slave_pty => 0 When a pseudo pty is used for the stdin stream, the slave side is auto +matically closed on the parent process after forking the ssh command. This option disables that feature, so that the slave pty can be access +ed on the parent process as $pty->slave. It will have to be explicitl +y closed (see IO::Pty).

The question is why you want to explicitly close the connection? As you said (I assume that the connection will be closed automatically when the object goes out of scope, but I prefer explicit than implicit behavior. :-)) well by reading this question Is it really required to explicitly close the SSH connection, channel or the telnet connection in Perl? the author of the module salva states:

If you don't close channels/connections, they will be automatically cl +osed for you from the objects destructors when they go out of scope. +The advantage of doing it explicitly is that you can catch errors.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Explicit closing connections with Net::SSH::Any by thanos1983
in thread Explicit closing connections with Net::SSH::Any by glasswalk3r

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.