Curl cannot read and write to files

Source: Internet
Author: User
Tags elastic search

Recently Learning es (elastic search), refer to the http://www.learnes.net/inside the official authoritative guide (later found that the official website has launched the Chinese version of the document). Some examples in this example simplify the command to access es as follows:

Curl-xget ' Localhost:9200/_count?pretty '-d ' {    "query": {        "Match_all": {}}    } '//simplified to get/_count{    " Query ": {        " Match_all ": {}}    }

and the command line can not enter, so think of a way to write a script, read a command file, the file is a simplified command, converted into a complete command after execution. I could have chosen Python or the shell, but after all it was PHP, so I decided to write it in PHP. PHP executes external commands in several ways, using Popen before, and then using them this time. Then execute the command when prompted: Writing body failed.

At first I thought it was es the wrong, into the ES log, found no logs. And then think that is not the time to send a command to the JSON data into a string when there is a problem, confirm that the discovery is not, the following will know the description of Curl document. This is a standard error for the Curl command because curl cannot write local files. What file did Curl write? Naturally is the pipe file, change a way to call the Curl command, instead of the PHP system method, the problem is resolved.

On Curl's error, StackOverflow also asked, although I have not found the real reason, but found an example of the same error: https://stackoverflow.com/questions/16703647/ Why-curl-return-and-error-23-failed-writing-body.

Although the use of pipe sometimes causes curl to fail, ice beauty is clear about why it failed. But there is a case for a certain failure: the pipe has commands to exit before Curl writes, such as Grep-qs foo. grep exits and closes the pipe after it finds Foo.

Curl-x GET ' http://php.net/manual/zh/function.uniqid.php ' | grep  -qs ' HTML '

Here need to choose a more content page, if you choose like ' www.baidu.com ' such a simple page, write pipe may be a one-time write out, will not error.

The Curl document can refer to http://aiezu.com/article/linux_curl_command.html.

Mark, please!

Curl cannot read and write to files

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.