Closed zxt5 closed 1 year ago
Hey @zxt539, here's an explanation from the docs:
What happens is that when HTTPie is invoked, for example, from a
cron
job,stdin
is not connected to a terminal.
Essentially, stdin
is a file descriptor, which may or may not point to a terminal—depending on the context in which HTTPie runs. If it’s not connected to a terminal, we try to read its contents because you might be piping in data (e.g., echo hello | http pie.dev/post
).
Under the hood, we call sys.stdin.isatty()
to find out:
Return
True
if the file descriptorfd
is open and connected to a tty(-like) device, elseFalse
.
You can test it by running the following command in different contexts (from the terminal, from java
, …):
# In the terminal it’s True
$ python3 -c 'import sys;print(sys.stdin.isatty())'
True
# …unless it’s redirected
$ echo hello | python3 -c 'import sys;print(sys.stdin.isatty())'
False
Here’s more on the TTY concept: http://www.linusakesson.net/programming/tty/
Got it! Thanks for your reply!
I am trying to use httpie from a Java program by using
ProcessBuilder
to run external commands.When I run "http -h google.com", the process hangs since it's waiting for
stdin
. But if I run the same command in a termial instead of in a jave program, it won't hang but print the output and exit.I know it can be fixed by using
--ignore-stdin
, but I am wondering why it does not hang when running in the terminal. What's the differences between these two situations?