Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [stdin]

stdin is the name of the default input file descriptor of a process. Since there is really nothing special about `stdin`, you *should not* use this tag. Use [tag:io-redirection] for questions on how to redirect input, use [tag:file-descriptors] for questions on how to manage file descriptors, use [tag:lock] for questions of file locking, and use [tag:files] for general questions on file operations.

0
votes
0answers
18 views

Redirection vs Process substitution: `echo foo | bar` vs `bar <( echo foo)` [duplicate]

What is the difference between these two constructs, echo foo | bar bar <( echo foo ) I thought both of them would set up STDIN the same way. However, that seems to not be the case for me (exact ...
0
votes
0answers
73 views

What is the '/dev/stdin'? [duplicate]

I am a very beginner of unix, and working on putty shell environment. I know standard input, output, and error are streams and related to file descriptors, but I did not understand clearly what /dev/...
1
vote
1answer
41 views

Why isn't it possible to read from `stdin` with `read` when piping a script to bash?

I'm not looking for work-arounds or solutions for the issue. I'm fine with it not working like that in bash. I just don't understand why it doesn't work. I'm looking for an in-depth answer why the ...
-1
votes
2answers
69 views

About stdin. Any example for `[n]<filename` when n~0?

Does 1<filename have any meaning?Perhaps it means "keyboard -> stdout"?
0
votes
1answer
38 views

Read paths on stdin and spawn a new interactive shell for each line

Say I have the results of a long-running process, like this: $ find $HOME -perm 777 Now, I could get the results in a pager like this: $ find $HOME -perm 777 | less and then cd to the relevant ...
2
votes
1answer
63 views

Redirect standard error of one command to standard input of another command

I wish to redirect standard error of one command to standard input of another command like g++ filename.cpp 'redirection' less
0
votes
0answers
55 views

Redirecting input bash

I have a program, that runs on only one Raspberry Pi, but could be run from multiple other computers (through SSH). When I run my program on the Pi, it runs as expected. To be able to run from crontab ...
1
vote
3answers
125 views

Why is it uncommon for stdin inputs to have option-like inputs, while common for command line arguments?

POSIX and GNU have their syntax styles for options. For all the commands that I have seen, they accept option-like inputs as command line arguments. Is it uncommon for a program to accept option-...
0
votes
1answer
78 views

Commands leaking characters to bash

While building a small expect script I noticed that, after executing the script, some characters were automatically on the input of bash. I have seen that on other programs before, but here I have ...
2
votes
1answer
91 views

How to redirect stdin using mkfifo? [closed]

I searched on askubuntu, stackoverflow and I found this: $ mkfifo fif.pipe $ bash script.sh < fif.pipe $ echo 'say HELLO' > fif.pipe (say command do something in the script) But after $ bash ...
5
votes
3answers
241 views

Portable way to invoke tar with a list of files from stdin

I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content. I had done this as follows: cd /path/to/files/ && find . -type f | cut -...
0
votes
0answers
149 views

Send string to another process stdin [duplicate]

Example process waiting an input sent to background $ read -p "Input text and hit ENTER to exit" & I try to write to stdin (fd/0) with \n $ echo -e "ok\n" > /proc/$!/fd/0 but $ fg read -p ...
0
votes
2answers
105 views

Why does libarchive's bsdtar's unzip throw away the permission bits when reading a ZIP-archive from stdin, but not directly?

I encountered that the command bsdtar from the package libarchive (under Arch Linux, at least) does throw away executable bits of files in .zip-archives when reading from stdin, but not when directly ...
8
votes
3answers
2k views

How to check if stdin is /dev/null from the shell?

On Linux, is there a way for a shell script to check if its standard input is redirected from the null device (1, 3) *, ideally without reading anything? The expected behavior would be: ./...
1
vote
1answer
25 views

A command wants file paths. How can I give it stdin for the “infile” and stdout for the “outfile”?

Consider a command like foo -in /path/to/infile -out /path/to/outfile, that you'd like to pass strings to rather than using temp files. It may be called a lot causing much disk access, or is related ...
1
vote
1answer
159 views

How does sponge (from moreutils) work?

sponge can “soak up” stdin and write it atomically to a file, enabling one to do cat f|sponge a. I want to know how exactly it accomplishes this. How does it know when the input is finished?
0
votes
2answers
64 views

After redirect stdin from tty1 to file, process still accepts input from tty1

command < file is used to redirect content from a file into a command. On virtual terminal 1 (/dev/tty1), I run less < file. Then on another virtual terminal, I run lsof -p <pid of the less ...
2
votes
1answer
386 views

What is non-standard input/output/error

I have read books/tutorials which mention standard input/output/error. My understanding is that: standard input/output/error are concepts of a process (i.e. if someone mentions standard input/output/...
3
votes
2answers
59 views

How does `cat`'s I/O model differ from that of other utilities?

From the output of stdbuf --help (GNU): Usage: stdbuf OPTION... COMMAND Run COMMAND, with modified buffering operations for its standard streams. ... NOTE: If COMMAND adjusts the buffering of its ...
-1
votes
2answers
106 views

How to terminate the script once the EOF of input file is reached?

I have to take input from a file for the script: $ ./script < input.txt My script runs an infinite while loop and you can come out of it only by pressing ctrl-d. How to add ctrl-d to input.txt ...
1
vote
1answer
30 views

Bash - redirected string not showing in output

I'm automating compilation and execution of C++ programs (+100 programs) which some of them require user interaction. Here is a sample of C++ program that requires user to insert a string: #include &...
1
vote
1answer
59 views

Proc stdin weird behaviour

Can sombody explain why this happening and how to fix it so that the data sent to stdin behaves the same way as the data typed in to stdin. For those who can't see the .gif Basically i have 3 ...
-1
votes
1answer
2k views

Why does echo <<EOF … EOF not work [duplicate]

Just wondering if anyone can explain why this works: echo `cat <<EOF {"branch":"foo","value":"bar"} EOF` but this doesn't: echo <<EOF {"branch":"foo","value":"bar"} EOF (the second ...
0
votes
0answers
100 views

Non-interactively change user in bash

I want to create a new user, add it to the sudo group and then change to that user not-interactively (i.e. without entering the password via stdin) in a test scenario on a vm. I tried this, but this ...
5
votes
3answers
672 views

Make tar from /dev/stdin file

What I'm looking for is a way to pass in arbitrary data through STDIN, and have it get tar'd up as if its a normal file. I tried this $ echo test | tar -cf test.tar /dev/stdin and that gives me a ...
1
vote
1answer
178 views

What are the purposes of `sudo -v &&` and `sh /dev/stdin` here?

From https://calibre-ebook.com/download_linux sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin What is the purpose of sudo -v && ...
4
votes
3answers
2k views

bash: Prompting for user input while reading file

I'm working on a bash script that parses a tab separated file. If the file contains the word "prompt" the script should ask the user to enter a value. It appears that while reading the file, the "...
0
votes
2answers
207 views

Why not write to stdin?

According to this answer, stdin, stdout, and stderr are all initially connected to the same place (same as /dev/tty), and the convention of reading from stdin and writing to stdout and stderr is only ...
2
votes
1answer
230 views

Why stdout won't flush when redirecting input from a fifo?

I have a program that displays a prompt message and waits for the user to input some text. $ program Input a line of text: <aaaa> Some more output. $ Now, I also want to be able to provide ...
0
votes
1answer
443 views

How to pass header from stdin or local file into remote curl?

The following curl command works as expected: $ curl -H @- -vso/dev/null http://www.example.com <<<"Foo:Bar" * Rebuilt URL to: http://www.example.com/ ... > Accept: */* > Foo:Bar > ...
4
votes
1answer
55 views

Determine if producer is outpacing consumer in pipeline

If I have: node foo.js | node bar.js is there a way to determine if there is a queue in between them that's building up? in other words if the producer is outpacing the consumer w.r.t. stdio?
0
votes
1answer
103 views

Repeatedly creating files named /dev/stdin can be dangerous?

In the third edition of "Learning the Bash shell" by Newham and Rosenblatt it is written in page 15 as a comment: if a particular UNIX utility doesn't accept standard input when you leave out the ...
0
votes
1answer
244 views

Read from named pipe and pipe to secondary process

I have this: delete_lock(){ first_arg=$1 } node x.js | delete_lock $0 < ${my_named_pipe} & I am looking to read from my_named_pipe into the stdin of the node.js process, and upon certain ...
3
votes
1answer
1k views

Problems caused by STDIN set to non-blocking mode

Certain commands start to consistently fail in a given terminal window: $ sudo apt-get install ipython ... After this operation, 3,826 kB of additional disk space will be used. Do you want to ...
1
vote
1answer
323 views

How does a temporary file differs from a pipe? [duplicate]

When one sends data (say stdout) to a temporary file, it is likely that something would be done with that data (the temporary file will be used as stdin for some process), then the temporary file will ...
1
vote
2answers
1k views

standard input: not a tty

Sometimes standard input (stdin) is a terminal: $ tty /dev/pts/0 Sometimes not: $ echo hello | tty not a tty $ tty < /dev/null not a tty $ tty << eof > hello > eof not a tty When "...
0
votes
2answers
194 views

Awk detect stdin

Perl, Ruby and PHP can detect stdin: $ perl -e 'print -t ? "no stdin" : "stdin"' no stdin $ echo | perl -e 'print -t ? "no stdin" : "stdin"' stdin $ ruby -e 'puts $stdin.isatty ? "no stdin" : "...
2
votes
1answer
148 views

How can I combine multiple 7z archives into one?

I'm trying to make a bash script that takes a large number of 7z archives and combines them into one archive. Here's what I have so far. #!/bin/bash DUMPPATH="/home/backups/dumps/" NEWPATH=$DUMPPATH"...
0
votes
1answer
60 views

Can reading STDIN conflict many writings from different processes? [closed]

One of my applications (Let's say "A") pushes its some alerts into STDIN and that app's shell script reads that STDIN and processes it. In the same way, there can be another applications (called B, C, ...
0
votes
1answer
443 views

Piping output from python to program results in infinite loop

I have a program that reads in input from the user and then prints out the memory location of where the input is stored in memory. It then asks if the users wishes to continue. When "Y" is entered, ...
0
votes
0answers
201 views

Redirecting stdin to java without bash

I'm making a kiosk like system, which reads data from a barcode reader, and a java program reads it from the console, and interprets it. I switched on autologin, and use crontab to run it like * * * *...
2
votes
2answers
780 views

How to use xargs with a command that requires user input?

I set up a pipe returning the name of a package I'd like to install using apt-get: ... | xargs -I _ sudo apt install _ However, apt-get can't read from stdin in this case and exits with: Do you ...
0
votes
2answers
157 views

How to find out what process is printing pages on remote printer through STDIN?

Some process sends output of my console over stdin to remote print server. If there is cups printer configured, it prints it. So I need to keep cups disabled. I suspect something is running lp or lpr. ...
1
vote
2answers
65 views

How does '-' work in bash redirection?

I have seen this explained somewhere before but can't find a reference now. An example usage from docker getting started guide for Ubuntu: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | ...
1
vote
2answers
100 views

read value validation

Is there a way to validate or confirm that the user wrote what it meant to write in read? For example, the user meant to write "Hello world!" but mistakenly wrote "Hello world@". This is very similar ...
-1
votes
2answers
621 views

stdin unbuffered

I'm executing a program with an stdin redirection: $ prog < f In that case, the stdin is fully buffered. Is there a trick to make it unbuffered or line buffered? EDIT. Without modifying the ...
1
vote
2answers
38 views

Pass value from command to another without writing to disk

I want to pass the output of one command into another without writing to disk, but the second command is interactive so passing the value into STDIN will prevent the second command from being ...
1
vote
1answer
50 views

Pass handle to stdin down pipeline

Say I have node foo.js | node bar.js is there a way to pass a handle on foo's stdin to bar? I have a rare case where I'd like to communicate backwards in the pipeline. At the least I know that I ...
2
votes
1answer
90 views

How to automate a keystroke to a cli terminal appilcation like ranger?

I'd like to send a keystroke to ranger, when I have ranger running and have gotten it's PID with: Output of ps aux | grep '[/]usr/bin/python -O /usr/bin/ranger': chris 5054 3.1 0.1 116248 ...
4
votes
3answers
843 views

Communicate backwards in a pipe

I have a simple pipeline: node foo.js | node bar.js bar.js will read from stdin to get data from foo.js. But what I want to do is ensure that bar.js gets one of the last messages from foo.js before ...