1

I've got a perl script that automatically logs me via ssh by spawning ssh with Expect.pm.

It actually works pretty well and here is my ouput:

    $ ngh bestServerEver
    GPG Pass : 
    root@**********'s password: 
    Linux **** 2.6.32-042stab059.7 #1 SMP Tue Jul 24 19:12:01 MSK 2012 x86_64 GNU/Linux
    motd!!!!!!!!!!
    Last login: Mon Feb  4 22:18:10 2013 from *******************
    bash
    [root@******:~]$ bash
    [root@******:~]$

I'm trying to suppress this output to get to the server shell directly after typing my command. Like that:

$ngh BestServerEver
root@server# 

I've tried that answer: How can I suppress STDOUT temporarily in a Perl program?

I've also tried:

    local (*OUT, *ERR);
    open OUT, ">&STDOUT";
    open ERR, ">&STDERR";
    close STDOUT;
    close STDERR;
    print "don't print";
    open STDOUT, ">&OUT";
    open STDERR, ">&ERR";

Both are okay when it's about standard STDOUT but Expect seems to be a different kind of handle or whatever.

I've also tried setting:

$exp->stty("-echo");

But it did not hide anything

Finally, here is my code http://pastebin.com/pSL3AwBW if you have some tips to give me on how to hide that junk.

Community
  • 1
  • 1
Azryel
  • 71
  • 1
  • 11

1 Answers1

2

The docs tell you to use

$exp->log_stdout(0);

Tested:

$ perl -MExpect -E'
   my $e = Expect->spawn("cat");
   $e->log_stdout($ARGV[0]);
   $e->send("abc\n"); $e->expect(undef, "abc");
   $e->send("def\n"); $e->expect(undef, "def");
   say "done."
' 1
abc
def
done.

$ perl -MExpect -E'
   my $e = Expect->spawn("cat");
   $e->log_stdout($ARGV[0]);
   $e->send("abc\n"); $e->expect(undef, "abc");
   $e->send("def\n"); $e->expect(undef, "def");
   say "done."
' 0
done.
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Well that helps a lot! thank you! But would I still get the output from the commands i send : when i send $exp->send("bash"); it ouputs : bash (then) [root@server:~]$ bash (then) [root@server:~]$ – Azryel Feb 04 '13 at 22:08
  • i might have done something wrong in my script since it actually does print it : with debug to 3, ---> Attempting interconnection ---> interconnect: read 51 byte(s) from spawn id(3). ---> Printed '\033[01;32m[root@server\033[00m:\033[01;34m~]\033[00m$ bash\r\n' to handle id(5) from spawn id(3). ---> [root@server:~]$ bash <--- But thanks anyway i'll try to figure it out ;) – Azryel Feb 05 '13 at 00:10