本篇內容介紹了“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://vcdvsql.cn/article42/gjogec.html
成都網站建設公司_創新互聯,為您提供ChatGPT、做網站、網站改版、動態網站、Google、定制網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯