&

Source: Internet
Author: User
& Amp; -- Linux general technology-Linux programming and kernel information in Linux commands. The following is a detailed description. It took a lot of time to debug a small project in the past few days. There are also some lessons.

It took me one morning to debug a small webpage capture module. The program is a Web page captured by wget in Linux. The problem at the time was that when I used gdb for single-step debugging, there was no problem at all. There are no problems with the desired link. However, once the program runs itself, it will be silly. More than 400 links can only capture a few of them, and sometimes file read/write errors occur. Very strange.

It's always there, because in many cases, cout clearly shows that it has been captured. I don't know why I can't write the captured file to the corresponding string. I thought there was something wrong with reading/writing a file or passing a string pointer. It was changed for half a day. It is also suspected that when the system calls the function system (), whether to regard wget as another program that is concurrently executed with the program. As a result, when the file is not captured, the file is read and written. However, I don't know who to ask. Very depressing.

The wget command is roughly like this:
Wget-O .tmp.html http://fc.sh365.com/rent.aspx? Id = 4545-fsdf44-fd & p = 2

After careful observation, wget captures are given in the prompt, and the string "& p = 2" in the actually captured link is gone. If something is wrong, it will cause the following link:

Wget-O .tmp.html "http://fc.sh365.com/rent.aspx? Id = 4545-fsdf44-fd & p = 2"

Everything finally runs according to my schedule and finds the problem. In the first command string, the symbol "&" is not considered as a part of the link,

The shell runs wget as a background program. As for "p = 2", it will be used as another command, and the parsing result will tell you that this command does not exist. In addition, the program continues to run forward, regardless of whether or not wget captures the webpage. Therefore, after the actual capture, the program has run.

Therefore, when debugging a program, do not doubt some basic things. For example, I always suspect that file reading and writing will go wrong, the pointer is disgusting, and it is easy to mess up. In fact, many errors do not concern them. We need to observe and compare them. Finally, we recommend that you be careful when using linux commands, such as the "&" symbol.

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.