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 the [io-redirection] tag for questions on how to redirect input, use [file-descriptors] for questions on how to manage file descriptors, use [lock] for questions of file locking, and use [files] for general questions on file operations.

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 the tag for questions on how to redirect input, use for questions on how to manage file descriptors, use for questions of file locking, and use for general questions on file operations.

309 questions
106
votes
9 answers

Bash: Assign output of pipe to a variable

I am trying to get the output of a pipe into a variable. I tried the following things: echo foo | myvar=$(
Parckwart
  • 1,061
  • 2
  • 8
  • 5
104
votes
10 answers

How to do nothing forever in an elegant way?

I have a program which produces useful information on stdout but also reads from stdin. I want to redirect its standard output to a file without providing anything on standard input. So far, so good: I can do: program > output and don't do anything…
a3nm
  • 8,978
  • 5
  • 28
  • 36
92
votes
7 answers

Can I pipe stdout on one server to stdin on another server?

stdout on one CentOS server needs to be piped to stdin on another CentOS server. Is this possible? Update ScottPack, MikeyB and jofel all have valid answers. I awarded the answer to Scott because, even though my question didn't specify security as a…
Wesley
  • 13,963
  • 12
  • 35
  • 49
88
votes
6 answers

How to pass password to mysql command line

I have MySQL password saved on a file foo.php, for example P455w0rd, when I try to use it: $ cat foo.php | grep '$dbpwd=' | cut -d '"' -f 2 | mysql -U root -p mydb -h friendserver Enter password: (holds) $ echo P455w0rd | mysql -u root -p mydb -h…
Kokizzu
  • 9,257
  • 12
  • 55
  • 82
45
votes
4 answers

"openssl dgst -sha1" producing an extraneous "(stdin)= " prefix and trailing newline

If you run this command on your Unix echo -n "foo" | openssl dgst -sha1 You will get this output: (stdin)= 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 (followed by a newline). How can I force openssl to not show the (stdin)= prefix, and avoid the…
SecurityClown
40
votes
2 answers

Piping data to a process's stdin without causing EOF afterward

I have an executable that starts a user-interactive shell. I would like to, upon launch of the shell, inject a few commands first, then allow the user to have their interactive session. I can do this easily using echo: echo "command 1\ncommand…
Jason R
  • 645
  • 1
  • 6
  • 11
36
votes
6 answers

How do I make python programs behave like proper unix tools?

I have a few Python scripts laying around, and I'm working on rewriting them. I have the same problem with all of them. It's not obvious to me how to write the programs so that they behave like proper unix tools. Because this $ cat characters |…
ixtmixilix
  • 13,040
  • 27
  • 82
  • 118
34
votes
3 answers

echo or print /dev/stdin /dev/stdout /dev/stderr

I want to print the value of /dev/stdin, /dev/stdout and /dev/stderr. Here is my simple script : #!/bin/bash echo your stdin is : $(
Omar BISTAMI
  • 551
  • 2
  • 7
  • 14
30
votes
3 answers

vim: Force specific syntax via command-line argument

When I want to easily read my PostgreSQL schema, I dump it to stderr and redirect it to vim: pg_dump -h localhost -U postgres dog_food --schema-only | vim - This gives: vim does not have a syntax highlight schema, because it has no filename…
Adam Matan
  • 2,543
  • 6
  • 29
  • 31
30
votes
3 answers

nohup: ignoring input and redirecting stderr to stdout

I am starting my application in the background using nohup as mentioned below - root@phx5qa01c:/bezook# nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --fsconfigdir /opt/exhibitor/conf --hostname…
arsenal
  • 3,053
  • 17
  • 44
  • 49
29
votes
2 answers

Linux : how to redirect stdout & stderr to logger?

I have a program I need to run at startup, it has output on stdout and stderr that I want to redirect to the system log using the logger command. What I have in my startup script is thie: /home/dirname/application_name -v|logger 2>&1 & This is…
fred basset
  • 1,025
  • 3
  • 15
  • 22
28
votes
5 answers

Create a virtual file that is actually a command

Is there any way to create a virtual file, such that reading from the file actually reads from the stdout of a command; writing to the file is acually writing to the stdin of a command? So far I have kludged this with an inotifywait on a file, which…
jsj
  • 1,400
  • 1
  • 16
  • 28
27
votes
6 answers

Bash function that accepts input from parameter or pipe

I want to write the following bash function in a way that it can accept its input from either an argument or a pipe: b64decode() { echo "$1" | base64 --decode; echo } Desired usage: $ b64decode "QWxhZGRpbjpvcGVuIHNlc2FtZQo=" $ b64decode <…
tyrondis
  • 373
  • 1
  • 3
  • 6
27
votes
4 answers

Why do some commands not read from their standard input?

I wonder what when we should use pipeline and when we shouldn't. Say for instance, to kill certain process which handling pdf files, the following will not work by using pipeline: ps aux | grep pdf | awk '{print $2}'|kill Instead, we can only do it…
sylye
  • 657
  • 1
  • 7
  • 13
1
2 3
20 21