简体   繁体   English

bash(带HTTPie)使用什么output?

[英]What output is used in bash (with HTTPie)?

I'm trying to analyze this command:我正在尝试分析此命令:

$ http :"/hello"
HTTP/1.1 401 Unauthorized
<headers>

<body>

I'm trying to save the whole thing in a variable VAR=$(... ) but to no avail so far.我试图将整个内容保存在变量VAR=$(... )中,但到目前为止无济于事。

If I run如果我跑

$ http :"/hello" 1>/dev/null

everything disappear, so I derive that everything is standard output.一切都消失了,所以我得出一切都是标准的 output。

But if I try to send this to a file or to my variable, I don't see the initial portion.但是,如果我尝试将其发送到文件或我的变量,我看不到初始部分。 So I thought this was stderr , so I did 2>&1 but this doesn't have any effect either.所以我认为这是stderr ,所以我做了2>&1但这也没有任何效果。

How can I go about understanding this?我怎么能理解这个?

Thanks谢谢

HTTPie alters its output, depending on whether it is writing to the terminal or a regular file. HTTPie 会更改其 output,具体取决于它是写入终端还是常规文件。

From the manual手册

Redirected output重定向 output

HTTPie uses a different set of defaults for redirected output than for terminal output. HTTPie 对重定向的 output 使用一组与终端 output 不同的默认值。 The differences being:区别在于:

Formatting and colors aren't applied (unless --pretty is specified).不应用格式化和 colors(除非指定--pretty )。 Only the response body is printed (unless one of the output options is set).仅打印响应正文(除非设置了 output 选项之一)。 Also, binary data isn't suppressed.此外,不会抑制二进制数据。

[...] [...]

There are specific command line options you can use to override the defaults.您可以使用特定的命令行选项来覆盖默认值。

You could try using option "-v" and "-o" to capture both headers and body in a file, as in:您可以尝试使用选项“-v”和“-o”来捕获文件中的标题和正文,如:

http -v -o output.file "google.com/bla"

As mentioned by @chepner in the comment, some tools detect if stdout is a file or not and change what they output.正如@chepner 在评论中提到的那样,一些工具检测标准输出是否是文件并更改它们 output 的内容。

Edit: to work easiest as you wanted (to stdout) you can use:编辑:为了你想要的最简单的工作(到标准输出),你可以使用:

http -v -o /dev/stdout "google.com/bla"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM