Run interactive programs in non-deliverable Mode

Source: Internet
Author: User
Article Title: Use a non-deliverable method to run interactive programs. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In order to improve the flexibility of software operation, applications often need to provide some user communication windows. In fact, in Unix operating systems, many commands themselves have the functions of interactive programs. For example, if a folder contains files or subfolders, the system will prompt you whether to delete the file or subfolders. This prevents users from accidentally deleting useful files. But sometimes this will also cause some trouble. For example, there may be 100 files in this folder and a 300 folder. If you want to delete a file every time you delete it, you need to follow the y expression below to delete the file, then you need to press 400 y. The design of this interactive program is obviously troublesome. To this end, in some specific circumstances, system engineers may want to run an interactive program in a non-interactive manner.

  1. Use in interactive programs < <符号。< strong>

The query command may be the most commonly used command in Unix systems. For example, a system engineer may need to search for a keyword in a script program. In the past, System Engineers had to open multiple target files in sequence and enter the desired strings for search. This method can also be used when the number of target files is small. However, if there are many target files, this would be a little too much work.

To improve user interaction, the search Command usually requires you to input parameters such as the name of the file that you want to search for when querying data. However, in actual work, the system engineer may need to perform a search name multiple times, and the content to be searched each time is the same (as described above ). At this point, if the system engineer waits for the command execution to end and then enters relevant parameters, this is obviously a waste of time. In this case, the system engineer needs to run the interactive program or command in non-interactive mode. Obviously, Unix system developers also consider this content. Therefore, they developed a < <符号文件可以帮助实现类似的功能。< p>

For example, lookforinfo. sh is a script program written by the author to find a keyword in a large file. Because this program is complicated, I will not list it here. In the future, I will have the opportunity to explain this script program. When running this program, you need to connect to a parameter. One is the string to be searched, and the other is the file to be searched. However, when I was running this program, I added < <符号,并且在后面加入了笔者需要查找的关键里以及需要查找的目标文件名。此时笔者运行这个程序的时候,就不需要输入这个两个参数了。笔者现在是每天利用cron命令让其执行一次,看看有没有在这个程序文件中出现start关键字。如果出现的话,则马上通过邮件方式告知笔者。这个run.sh是某个程序启动时的日志文件。当启动出现警告或者错误信息的时候,就会有一个error开头的记录。为此,通过这个每次一次的查询文件(时间设置在这个程序启动后10分钟),笔者在不查看这个日志文件的情况下,就可以知道其启动过程中是否有错误信息。要实现这个功能,<<文件在这里起着至关重要的作用。< p>

So here < <文件到底有什么作用呢?<<符号其实表示一个文件,系统工程师往往把它称之为here文件。shell会使用<<这个符号表示从脚本所在的同一个文件中读取数据。如所示,就表示从脚本的同一个文件中读取相关参数,而不是从其他文件(如键盘)中读取数据。通常情况下,任何使用标准数据的命令都可以从here文档中读取相关的参数数据。如所示,本来执行lookforinfo.sh程序,需要从键盘中接收查询字符串以及目标文件名两个参数。而此时笔者利用了<<文件,则系统看到了这个关键字之后,就不会再等待笔者键盘上的输入,而直接从here文件中去读取相关的运行参数。为此,当系统每次周期性的运行这个脚本程序时,系统就会自动获取相关的参数,而不用笔者重复的输入。可见,利用here这个文件符号可以让一些交互式的命令采用预先定义好的参数以非交互式的方式来执行。这个特性很有用。如上面笔者就是利用这个功能让系统定期的查询应用程序启动日志,看看是否有错误信息。让系统来帮助系统工程师自动监测应用程序的启动情况,从而降低系统工程师的工作量。< p>

In addition, system engineers may also like to use read statements in applications. However, the read Statement requires a set of pre-determined parameters to respond. In this case, if the system engineer can pre-prevent these parameters in the here document, the interactive command read can also be run in non-interactive mode. With this processing technique, the system can reduce the waiting time for user input and improve the program execution efficiency. Because computers respond much faster than the human brain. If you can provide related parameters to interactive commands or programs in advance, it may take 10 seconds to execute them. However, if you enter relevant parameters during execution, including the user's reflected time and input time, the command may take 60 seconds to complete. For this reason, System Engineers can write some simple script programs to run some interactive commands in non-interactive environments, thus improving the application execution efficiency.

[1] [2] [3] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.