首页 > 解决方案 > 无法在 .sh 脚本中使用“&”作为后台 HTTPie http 请求

问题描述

这是如何从 BASH 提示中工作的:

/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

{}

...但从 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>

?

编辑:http是 HTTPie

编辑:type httphttp is hashed (/testproj/env/bin/http)

编辑:一个人可以重现错误http http://www.google.com </dev/null &(感谢@e36freak)

编辑:来自 IRC 上的 e36freak:

这似乎是一个问题,stdin
我得到了同样的错误,只是http http://www.google.com </dev/null
httpstdin附加到tty它看起来
无论出于何种原因
在手册页中找不到它,但我确定它就在那里

标签: bashhttpiebackgrounding

解决方案


您最喜欢需要包含--ignore-stdin阻止 httpie 尝试读取它的选项。参见:https ://httpie.org/doc#scripting


推荐阅读