0

I am a junior java developer and I am new to UNIX system.

I don't know I am asking a right question or not.

So, in a IDE environment, a STDIN usually refers to IDE's console.

In a UNIX shell, it seems like STDIN refers to command line prompt.

So how many STDIN can exist in a shell session?

Is there any other input stream than shell prompt? (something like non-standard input,output)

  • this explain a bit : https://unix.stackexchange.com/questions/60641/linux-difference-between-dev-console-dev-tty-and-dev-tty0 – Archemar Jul 03 '20 at 06:44

1 Answers1

3

Think differently:

Every process has a number of file descriptors. The first three of those are, by convention, stdin, stdout, and stderr.

When you run a process, you can "point" those descriptors to different places.

When you run a shell in an IDE, the IDE points those to the console the IDE provides.

When you run a shell in an xterm, the xterm points those to the window/keyboard interaction the xterm provides.

When you run a shell via a serial port (common for embedded systems), then those point to the serial port.

When you run a shell from a shell and redirect them, you can point them to a file.

In the same way, when you run some other process (program) from a shell, you can redirect stdin and stdout for this program, e.g. via > and <.

"STDIN refers to command line prompt." makes no sense. You can say that the shell process itself has those descriptors, they refer to whatever was set when the shell was invoked, and the shell can inherit those to other programs that are started from the shell (or use different ones for those).

dirkt
  • 32,309
  • Would also add: in the absence of any redirection or modification, every child process inherits copies of all file descriptors from its parent. Every time a shell constructs a pipe a | b between processes, a pair of processes get streams a->stdout and stdin->b. For a shell compound statement' every child in the block inherits every open file descriptor. – Paul_Pedant Jul 03 '20 at 09:21
  • Thank you so much, this explanation rocks! – ikaruga_oboro Jul 03 '20 at 11:21