温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

expect中\t和\n区别是什么

发布时间:2021-07-30 17:19:02 来源:亿速云 阅读:207 作者:chen 栏目:大数据

本篇内容介绍了“expect中\t和\n区别是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

spawn后 send 最后都追加一个回车符\r。因为这是程序之间的交互,用的是回车。

但是没有spawn的情况下,send后面追加的是\n。这是方便输出到终端的操作。

参考:

expect "hi\n"
send "hello there!\n"

I typed the string hi and then pressed return. My input matched the pattern " hi\n ". Ideally, a return would be matched with " \r "; however, the UNIX terminal driver translates a return to " \n ".2 As you will see later on, it is rarely necessary to have to worry about this mapping because most of Expect's interactions occur with programs not users, and programs do not "press return". Nonetheless, it is occasionally useful to expect input from people.Plus, it is much easier to experiment with Expect this way.

我输入的字符串hi,然后按下回车。我的输入匹配模式“hi\n”。理想情况下,回车与“\r”相匹配; 然而,UNIX终端驱动将回车转换成"\n"。正如你将在后面看到,很少需要担心这个映射,因为大部分Expect的交互发生在程序中而不是用户侧,程序并不”按回车“。尽管如此,在期望从用户输入时这偶尔是有用的,另外,这是很容易使用Expect进行实验。

expect "Name"
send "anonymous\r"
expect "Password:"
send "don@libes.com\r"
expect "ftp> "

It is a common mistake to terminate send commands to a process followed by \n . In this context, \n denotes a linefeed character. You do not interactively end lines with a linefeed. So Expect must not either. Use " \r ".

这是一个常见的错误去使用\n来终止关联到一个进程的send命令。在这种情况下,\n表示换行字符。你不会使用换行符结束一行。所以Expect来不会。这里使用“\r”。

Contrast this to what I was doing earlier -- sending to a user, or rather, standard output. Such strings were indeed terminated with a \n . In that context, the \n denotes a newline. Because standard output goes to a terminal, the terminal driver translates this to a carriage-return linefeed sequence.
Similarly, when reading lines from a program that would normally appear on a terminal, you will see the carriage-return linefeed sequence. This is represented as \r\n in an expect pattern.

将这个和我之前做的相对比 - 发送给用户,或者更确切地说,标准输出。这样的字符串确实是使用\n来终止的。在这种情况下,\n表示新的行。由于标准输出到终端,终端驱动将其转换成回车换行序列。

同样,在终端上从程序读入行的时候,你会看到回车换行序列。这表示为Expect模式中的\r\n。

This may seem confusing at first, but it is inherent in the way UNIX does terminal I/O and in the representation of characters and newlines in strings. The representation used by Tcl and Expect is common to the C language and most of the UNIX utilities. I will have more to say on the subject of newlines and carriage returns in .


第一眼看起来似乎是令人困惑的,但它是固有的UNIX处理终端I/O的方式,和字符串中的字符和换行符的表示方式。使用Tcl和Expect的表示是和C语言和大部分的UNIX工具是共通的。我将在换行和回车的主题中做更多的阐述。

“expect中\t和\n区别是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI