您好,登錄后才能下訂單哦!
本篇內容介紹了“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區別是什么”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。