rajpython
rajpython

Reputation: 179

python pexpect failing for curl output

I am capturing a curl output after spawning to a remote machine. The expect function keeps getting timed out , i tried different patterns still no luck. The curl request is of the form ,

hdl2.sendline("curl -v http://{0}/index.html -o /dev/null".format(host1))

The output received is

" > GET /index.html HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 13.126.208.1
> Accept: */*

< HTTP/1.1 200 OK
< Date: Sun, 20 Aug 2017 12:32:54 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< Last-Modified: Sun, 20 Aug 2017 09:56:44 GMT
< ETag: "2cf6-5572c61363668"
< Accept-Ranges: bytes
< Content-Length: 11510
< Vary: Accept-Encoding
< Content-Type: text/html
< 
{ [data not shown]
100 11510  100 11510    0     0  3055k      0 --:--:-- --:--:-- --:--:-- 3746k
* Connection #0 to host 13.126.208.1 left intact
ubuntu@ip-172-31-28-48:~$ "

This is the end output , i have given expect as

hdl2.expect("\$ ")

But every time i get pexpect timeout. Any suggestions is appreciated.

Upvotes: 0

Views: 339

Answers (2)

Kirill Bulygin
Kirill Bulygin

Reputation: 3826

This may happen because of line buffering: ubuntu@ip-172-31-28-48:~$ is not terminated with \n, so expect may not consider this line. You can try this:

hdl2.sendline("curl -v http://{0}/index.html -o /dev/null; echo DONE".format(host1))
hdl2.expect("DONE")

(Use a string that will be unique for your data instead of DONE.)

Upvotes: 2

pynexj
pynexj

Reputation: 20698

Pexpect's default timeout is 30 seconds. If your curl command needs more time then you need to increase the timeout value. For example:

hdl2.expect("\$ ", timeout=600)

Upvotes: 1

Related Questions