Thanks salva for your reply, but it's not quite what i am looking for.
Think about my sx thingie like it's gnu screen. I would like to ssh 'into' screen directly, instead of launching it as a command.

i noticed also other thing: while running commands in loop, they're acting like being launched over separate ssh connections. Consider following code

use strict; use warnings; use Net::OpenSSH; use MIME::Base64; my $host = $ARGV[0]; my $ssh = Net::OpenSSH->new(user => 'user', password => decode_base64('my_b64_encoded_ +pass'), host => $host, timeout => '3', # master_stderr_discard => 1, # master_opts => [-o =>'RemoteCommand="sx s +u - targetuser"'] ); die "Can't ssh to $host: " . $ssh->error if ($ssh->error); foreach my $cmd('echo "VAR=$VAR"', 'id', 'export VAR="test";echo $VAR', 'echo "VAR=$VAR"') { my $output=$ssh -> system ($cm +d); $ssh->error and warn "$cmd didn't complete successfully: ". $ssh->error; print $output; }
It produces output
VAR=
1uid=xxx(user) gid=yyy(group)
1test
1VAR=

I didn't found method which allows "connection" to be kept between system() or capture() calls, or i am doing something awfully wrong.
My ultimate goal is to check exitcode after each line of (externally loaded) script and perform action if something fails, but without some initializations with exporting variables my whole idea collapses :/
i don't want to produce nasty workaround like env > /tmp/envfile and sourcing it prior to actual command.

Does Openssh foresee mechanism to continue/append to existing connection? I love concept of warn $ssh-> error if $ssh-> error, hence i don't want to look for other modules, and surely i don't want to utilize any Expect-like tools.


In reply to Re^2: Net::Openssh spawn other process than shell by lis128
in thread Net::Openssh spawn other process than shell by Anonymous Monk

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.