Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between\ t and\ nin expect?

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the difference between\ t and\ nin expect". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

After spawn, send finally appends a carriage return character\ r. Because this is the interaction between programs, using enter.

But in the case of no spawn, send is appended\ n. This is a convenient operation to output to the terminal.

Reference:

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.

I typed the string hi and pressed enter. My input matches the pattern "hi\ n". Ideally, carriage returns match "\ r"; however, the UNIX terminal driver converts carriage returns to "\ n". As you will see later, there is little need to worry about this mapping, because most Expect interactions take place in the program rather than on the user side, and the program does not "press enter". However, this is occasionally useful when expecting input from the user, and it is easy to experiment with 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".

This is a common mistake to use\ nto terminate send commands associated with a process. In this case,\ n represents a newline character. You don't end a line with a newline character. So Expect won't come. Use "\ r" here.

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.

Compare this to what I've done before-send it to the user, or rather, standard output. It is true that such a string is terminated with\ n. In this case,\ nrepresents a new line. As the standard output to the terminal, the terminal driver converts it into a carriage return newline sequence.

Similarly, when you read a line from a program on the terminal, you will see the enter newline sequence. This is represented as\ r\ n in Expect mode.

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.

It may seem confusing at first glance, but it is inherent in the way UNIX handles the terminal Imax O, and the representation of characters and newline characters in strings. Representations using Tcl and Expect are common to the C language and most UNIX tools. I will elaborate more on the topics of line breaking and carriage return.

This is the end of the content of "what's the difference between\ t and\ nin expect". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report