亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4667 | 回復: 2
打印 上一主題 下一主題

IO::Pty could not connect pty as controlling terminal! [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-08-29 18:56 |只看該作者 |倒序瀏覽
30可用積分
本帖最后由 lucash 于 2010-08-29 19:08 編輯

在結合使用Net::OpenSSH 和 Expect模塊時,遇到的問題。

用Net::OpenSSH 建立一個master ssh connection ,然后用一個叫做open2pty的方法來
打開一個pty供Expect模塊使用。
在spawn時出錯,提示信息如下:

warning: TIOCSCTTY failed, slave might not be set as controlling terminal: Operation not permitted at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/IO/Pty.pm line 120.
Error: could not connect pty as controlling terminal!

但不知道怎么才能正確的使用IO::Pty中的make_slave_controlling_terminal() 方法來spawn一個子進程。
該方法的說明文檔中提示說只能通過fork一個子進程來調(diào)用它。不知道該如何使用。

我的出錯代碼如下:


  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Net::OpenSSH;
  4. use Expect;

  5. my $ssh = Net::OpenSSH->new('192.168.10.100',
  6.                  user       => 'lucash',
  7.                  passwd  => 'lucash'
  8. );
  9. $ssh->error and die "Unable to connect: " . $ssh->error . "\n";
  10. my @cmd = qw(who);
  11. my ($pty,$pid)  = $ssh->open2pty({},@cmd);
  12. my $exp = Expect->init($pty) or die "Can not init pty: $!\n";

  13. $exp->spawn(@cmd) or die "Unable to spawn command: $!\n";

復制代碼
加了make_slave_controlling_terminal后還是報錯:


  1. my ($pty, $pid)  = $ssh->open2pty({},@cmd};
  2. if ( (my $ppid = fork()) == 0) {
  3.       $pty->slave();
  4.       $pty->make_slave_controlling_terminal();
  5.       my $exp = Expect->init($pty) or die "Can not init pty : $!\n";
  6. }

復制代碼
難道是要open2pty得到的那個$pid fork的子進程中make_slave_controlling_terminal()才有用嗎?該怎么做呢?

以下是IO::Pty的部分源碼:
  1. [font=Verdana]
  2. sub make_slave_controlling_termianl {

  3.     …………………… 部分省略。
  4.    
  5.   # Acquire a controlling terminal if this doesn't happen automatically
  6.   if (defined TIOCSCTTY) {
  7.     if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
  8.       warn "warning: TIOCSCTTY failed, slave might not be set as controlling terminal: $!" if $^W;
  9.     }
  10.   } elsif (defined TCSETCTTY) {
  11.     if (not defined ioctl( ${*$self}{'io_pty_slave'}, TCSETCTTY, 0 )) {
  12.       warn "warning: TCSETCTTY failed, slave might not be set as controlling terminal: $!" if $^W;
  13.     }
  14.   }

  15.   if (not open(\*DEVTTY, "/dev/tty")) {
  16.     warn "Error: could not connect pty as controlling terminal!\n";
  17.     return undef;
  18.   } else {
  19.     close \*DEVTTY;
  20.   }
  21.    return 1
  22. }
復制代碼
IO:: Pty的文檔還說:
  1. See the try script (also test.pl) for an example how to correctly spawn a subprocess.
復制代碼
天哪,這個‘try’ 腳本在哪啊?

搞兩天了也沒搞定,各位大俠幫幫忙。多謝了。

注:這個部分只是一個腳本中的一小部分,因此暫不考慮拋棄Net::OpenSSH模塊的方法

論壇徽章:
0
2 [報告]
發(fā)表于 2010-08-30 11:37 |只看該作者
怎么都沒人來幫忙啊

論壇徽章:
0
3 [報告]
發(fā)表于 2010-08-30 17:23 |只看該作者
印象中自己遇見過類似的問題,剛剛特地去翻開自己以前寫過的代碼看了下
  1. 420     my $session = Net::SSH::Expect->new (
  2. 421         host => "$host",
  3. 422         password=> "$pass",
  4. 423         user => "$user",
  5. 424         raw_pty => 1
  6. 425     );
復制代碼
看來自能幫頂了

順便假設一下:如果我今天我也遇到跟你一樣的困境,我想我的Google思線是
首先看有先烈  Google之 "Error: could not connect pty as controlling terminal!" ,5分鐘內(nèi)找不到雷同的解決問題方案,那就可能該不能那么輕浮咯,安靜思考下"what is tty",也許就可以找到問題的根源咯,再不行就踏踏實實的看下源碼吧:)

以上思路 純屬愚見,望大家共同探討:wink:
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP