免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4182 | 回复: 1
打印 上一主题 下一主题

expect中的exp_send中包含中文,产生乱码,寻求解决方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-05 15:42 |只看该作者 |倒序浏览
spawn telnet 172.16.8.228

Trying...

Connected to 172.16.8.228.

Escape character is '^]'.

Local flow control on

Telnet TERMINAL-SPEED option ON



HP-UX vm-qw02 B.11.31 U ia64 (te)



login: ucapes

Password:

Last successful login:       Thu Jul  5 15:29:15 EAT 2012 172.16.8.229  

Last authentication failure: Thu Jul  5 10:32:08 EAT 2012 ::ffff:172.16.8.227  

Please wait...checking for disk quotas

(c)Copyright 1983-2006 Hewlett-Packard Development Company, L.P.

(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California

(c)Copyright 1980, 1984, 1986 Novell, Inc.

(c)Copyright 1986-2000 Sun Microsystems, Inc.

(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology

(c)Copyright 1989-1993  The Open Software Foundation, Inc.

(c)Copyright 1990 Motorola, Inc.

(c)Copyright 1990, 1991, 1992 Cornell University

(c)Copyright 1989-1991 The University of Maryland

(c)Copyright 1988 Carnegie Mellon University

(c)Copyright 1991-2006 Mentat Inc.

(c)Copyright 1996 Morning Star Technologies, Inc.

(c)Copyright 1996 Progressive Systems, Inc.



Confidential computer software. Valid license from HP required for

possession, use or copying.  Consistent with FAR 12.211 and 12.212,

Commercial Computer Software, Computer Software Documentation, and

Technical Data for Commercial Items are licensed to the U.S. Government

under vendor's standard commercial license.



You have mail.

$ ssh ucapes\@172.16.8.228

Password:

Last successful login:       Thu Jul  5 15:30:03 2012 vm-qw02  

Last authentication failure: Thu Jul  5 10:32:08 2012 ::ffff:172.16.8.227  

Last login: Thu Jul  5 15:30:11 2012 from 172.16.8.227


(c)Copyright 1983-2006 Hewlett-Packard Development Company, L.P.

(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California

(c)Copyright 1980, 1984, 1986 Novell, Inc.

(c)Copyright 1986-2000 Sun Microsystems, Inc.

(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology

(c)Copyright 1989-1993  The Open Software Foundation, Inc.

(c)Copyright 1990 Motorola, Inc.

(c)Copyright 1990, 1991, 1992 Cornell University

(c)Copyright 1989-1991 The University of Maryland

(c)Copyright 1988 Carnegie Mellon University

(c)Copyright 1991-2006 Mentat Inc.

(c)Copyright 1996 Morning Star Technologies, Inc.

(c)Copyright 1996 Progressive Systems, Inc.



Confidential computer software. Valid license from HP required for

possession, use or copying.  Consistent with FAR 12.211 and 12.212,

Commercial Computer Software, Computer Software Documentation, and

Technical Data for Commercial Items are licensed to the U.S. Government

under vendor's standard commercial license.



You have mail.

$ ssh ucapes\@172.16.8.229

Password:

Last successful login:       Thu Jul  5 15:30:09 2012 172.16.8.228  

Last authentication failure: Thu Jul  5 14:37:50 2012 172.16.8.228  

Last login: Thu Jul  5 15:30:21 2012 from 172.16.8.228


(c)Copyright 1983-2006 Hewlett-Packard Development Company, L.P.

(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California

(c)Copyright 1980, 1984, 1986 Novell, Inc.

(c)Copyright 1986-2000 Sun Microsystems, Inc.

(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology

(c)Copyright 1989-1993  The Open Software Foundation, Inc.

(c)Copyright 1990 Motorola, Inc.

(c)Copyright 1990, 1991, 1992 Cornell University

(c)Copyright 1989-1991 The University of Maryland

(c)Copyright 1988 Carnegie Mellon University

(c)Copyright 1991-2006 Mentat Inc.

(c)Copyright 1996 Morning Star Technologies, Inc.

(c)Copyright 1996 Progressive Systems, Inc.



Confidential computer software. Valid license from HP required for

possession, use or copying.  Consistent with FAR 12.211 and 12.212,

Commercial Computer Software, Computer Software Documentation, and

Technical Data for Commercial Items are licensed to the U.S. Government

under vendor's standard commercial license.



You have mail.

$ export PS1='<ucapes/>'

<ucapes/>===================select a from t where b=''dfsdf好的''===============

export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'

echo ...........sql start...........

<ucapes/>...........sql start...........

<ucapes/>sqlplus -S ucapes/ucapes\@capes227 <<EOF

> SET line 255

> SET FEED off

> set serveroutput on size 1000000

> declare      

>        v_cursor integer;

>        v_desc_tab dbms_sql.desc_tab;

>        v_rows integer;

>        v_value varchar2(1024);

> begin  

>        v_cursor := dbms_sql.open_cursor;

>        dbms_sql.parse(v_cursor, 'select a from t where b=''dfsdf:C5D''', dbms_sql.native);

>        dbms_sql.define_column(v_cursor, 1, v_value,1024);

>        v_rows := dbms_sql.execute(v_cursor);

>        if dbms_sql.fetch_rows(v_cursor) > 0 then

>           dbms_sql.column_value(v_cursor, 1, v_value);

>           dbms_output.put_line(v_value);

>         else

>           dbms_output.put_line(SQLERRM);

>         end if;

>           dbms_sql.close_cursor(v_cursor);

> exception

>           when others then

>               dbms_sql.close_cursor(v_cursor);

>               dbms_output.put_line(SQLERRM);

> end;               

> /

> exit

> EOF

ORA-0000: normal, successful completion

<ucapes/>echo ...........cmd end...........

...........cmd end...........

<ucapes/>exit

exit

logout

Connection to 172.16.8.229 closed.


$ exit

logout

Connection to 172.16.8.228 closed.


$ exit

logout

Connection closed by foreign host.

以上是我的输出日志,puts出来的中文时正常的,在exp_send时产生了乱码。其中 dfsdf好的 变成了 dfsdf:C5D
主机的字符集设置的是 LANG=zh_CN.hp15CN 请大侠么告之我,也试图用iconv转编码 不过不成功

论坛徽章:
0
2 [报告]
发表于 2012-09-20 11:18 |只看该作者
请问这个问题有结果么?
我也遇到相似的问题,我用expect脚本send中文的时候,回将数据double一份,我的脚本如下:
package require Expect
log_file -noappend "D:/tmp/exp.log"
spawn telnet 10.153.88.30
expect "login:"
send "wds\r"
expect "word:"
send "wdswds\r"
expect "$"
send "总\r"
expect "$"

经过我分析"总"这个字网络编码应该是\327\334

我单独起telnet进程发送"总"正常,网络编码为\327\334

然而通过expect send 出去抓包得到的数据却便问\327\327\334\334,相当于把数据double了一份

这个问题直接导致数据出错,请各位大虾指点指点。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP