P i
P i

Reputation: 30674

Cannot background HTTPie http request with `&` in .sh script

How come this works from the BASH prompt:

/testproj> http http://localhost:5000/ping/ &
[1] 10733
(env)
/testproj> HTTP/1.0 200 OK
Content-Length: 2
Content-Type: application/json
Date: Sat, 17 Nov 2018 19:27:01 GMT
Server: Werkzeug/0.14.1 Python/3.6.4

{}

... but fails when executed from in a .sh:

/testproj> cat x.sh
http http://localhost:5000/ping/ &
(env)
/testproj> ./x.sh
(env)
/testproj> HTTP/1.0 405 METHOD NOT ALLOWED
Allow: GET, HEAD, OPTIONS
Content-Length: 178
Content-Type: text/html
Date: Sat, 17 Nov 2018 19:29:00 GMT
Server: Werkzeug/0.14.1 Python/3.6.4
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>



<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

?

EDIT: http is HTTPie

EDIT: type http gives http is hashed (/testproj/env/bin/http)

EDIT: One can reproduce the error with just http http://www.google.com </dev/null & (Thanks @e36freak)

EDIT: from e36freak on IRC:

it appears to be an issue with stdin
i get the same error with just http http://www.google.com </dev/null
http wants stdin to be attached to a tty it looks like
for whatever reason
couldn't find it in the man page but i'm sure it's out there

Upvotes: -1

Views: 320

Answers (1)

Jakub Roztocil
Jakub Roztocil

Reputation: 16232

You most like like need to include the --ignore-stdin option to prevent httpie from trying to read it. See: https://httpie.org/doc#scripting

Upvotes: 1

Related Questions