网站建设资讯

NEWS

网站建设资讯

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

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

目前累计服务客户近1000家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站设计、做网站、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联公司始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。

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区别是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


本文标题:expect中\t和\n区别是什么
文章地址:http://cdweb.net/article/gjogec.html