Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
1
votes
0
answers
87
views
Using socat to redirect docker attach's STDIN/STDOUT to a TCP socket
I'd like to use `socat` to redirect the `STDIN/STDOUT` of the process executing `docker attach ` to a listening `TCP` socket on my Linux system. root@eve-ng:/opt/unetlab# tty /dev/pts/2 root@eve-ng:/opt/unetlab# root@eve-ng:/opt/unetlab# socat EXEC:'/usr/bin/docker attach afe29573-0030-4a69-8b3e-c04...
I'd like to use
socat
to redirect the STDIN/STDOUT
of the process executing docker attach
to a listening TCP
socket on my Linux system.
root@eve-ng:/opt/unetlab# tty
/dev/pts/2
root@eve-ng:/opt/unetlab#
root@eve-ng:/opt/unetlab# socat EXEC:'/usr/bin/docker attach afe29573-0030-4a69-8b3e-c04ededa8db7-0-4',pty TCP4-LISTEN:32000 &
1275378
root@eve-ng:/opt/unetlab#
The options for socat
are the following:
- EXEC:,pty
to say socat
to start a process executing ` allocating a pseudo-terminal
pty attached to its
STDIN/STDOUT (
socat actually opens the master side multiplexer
/dev/ptmx and then the
fd for the pseudo-terminal pair's master
ptm`)
- TCP4-LISTEN:32000
to say socat
to open a tcp
socket listening on port 32000
Indeed, in another terminal you can check:
root@eve-ng:~# tty
/dev/pts/5
root@eve-ng:~#
root@eve-ng:~# ps -ef | grep attach
root 1275378 1210230 0 08:43 pts/2 00:00:00 socat EXEC:/usr/bin/docker attach afe29573-0030-4a69-8b3e-c04ededa8db7-0-4,pty TCP4-LISTEN:32000
root 1275379 1275378 0 08:43 pts/2 00:00:00 /usr/bin/docker attach afe29573-0030-4a69-8b3e-c04ededa8db7-0-4
root@eve-ng:~#
docker attach
actually attaches to a process running inside the container executing the exec
executable, by the way you can see pts/1
is allocated to it (the container indeed was created using docker create -it
)
root@eve-ng:~# ps -ef | grep exec
root 1284441 731051 2 08:52 pts/1 00:00:00 exec
root 1284583 1222614 0 08:53 pts/5 00:00:00 grep --color=auto exec
root@eve-ng:~#
The problem I'm facing to is that connecting to the tcp socket 127.0.0.1:32000
from a telnet
client, the login process inside the container (exec
) doesn't work as expected. It seems the username typed in (carlo
) is repeated again not allowing to successfully login into the container.
Username: carlo
carlo
Password:
RP/0/RP0/CPU0:Jun 20 09:00:59.739 UTC: exec: %SECURITY-LOGIN-4-AUTHEN_FAILED : Failed authentication attempt by user '' from 'console' on 'con0_RP0_CPU0'
User Access Verification
Username:
Can you help me in understanding why ? Thanks.
P.s. digging into it using strace
I noticed that socat
actually reads from the relevant fd
(of type tcp socket
) twice instead of just once.
CarloC
(385 rep)
Jun 20, 2025, 09:05 AM
• Last activity: Jun 22, 2025, 07:17 PM
4
votes
1
answers
2083
views
Run vsim from dmenu — it only works when directly invoked in the terminal
- Works: `vsim`, `sh -c vsim` - Doesn't work: `echo "vsim" | sh`, `echo "vsim" | xargs -I {} sh -c "{}"` I want to run ModelSim (`vsim`) with [`dmenu`][1], which is triggered using `xbindkeys`. --- ### Details `vsim` is a executable for ModelSim, installed in `/opt/altera/modelsim_ase/bin`. When I r...
- Works:
vsim
, sh -c vsim
- Doesn't work: echo "vsim" | sh
, echo "vsim" | xargs -I {} sh -c "{}"
I want to run ModelSim (vsim
) with dmenu
, which is triggered using xbindkeys
.
---
### Details
vsim
is a executable for ModelSim, installed in /opt/altera/modelsim_ase/bin
.
When I run it directly, it runs. But when I run it with xargs
(eg. from dmenu), it does not work at all - the script itself launches, but probably in the wrong directory or something, I'm really clueless what's wrong.
My path (I added newlines for clarity):
[ondra@x201 ~]$ echo $PATH
/usr/local/sbin:
/usr/local/bin:
/usr/bin:
/usr/lib/jvm/default/bin:
/usr/bin/site_perl:
/usr/bin/vendor_perl:
/usr/bin/core_perl:
/opt/altera/quartus/bin:
/opt/altera/modelsim_ase/bin:
/home/ondra/bin:
/home/ondra/.gem/ruby/2.1.0/bin:
/opt/altera/University_Program/Monitor_Program/bin/bin
Where is vsim
?
[ondra@x201 ~]$ which vsim
/opt/altera/modelsim_ase/bin/vsim
Run it with xargs
:
[ondra@x201 ~]$ echo "vsim" | xargs -I {} sh -c '{} &'
[ondra@x201 ~]$ Reading /opt/altera/modelsim_ase/tcl/vsim/pref.tcl
# 10.1d
#
#
^C
Run it directly:
[ondra@x201 ~]$ vsim
Reading /opt/altera/modelsim_ase/tcl/vsim/pref.tcl
# --- and modelsim starts fine now ---
Any ideas welcome.
MightyPork
(1242 rep)
Nov 18, 2014, 10:12 AM
• Last activity: Jun 20, 2025, 11:04 PM
48
votes
1
answers
13460
views
What's wrong with var=$(</dev/stdin) to read stdin into a variable?
We've seen a few posts here lately that use this: ``` var=$(</dev/stdin) ``` in an attempt to read the shell's standard input into a variable. That is however not the correct way to do it on Linux-based systems and Cygwin at least. Why? What are the correct ways?
We've seen a few posts here lately that use this:
var=$(
in an attempt to read the shell's standard input into a variable.
That is however not the correct way to do it on Linux-based systems and Cygwin at least.
Why? What are the correct ways?
Stéphane Chazelas
(579282 rep)
Sep 7, 2022, 08:22 AM
• Last activity: Apr 11, 2025, 10:19 AM
1
votes
1
answers
2409
views
Send more than one line to an executable using bash
So python has a convenient function as part of `pwntools` where one can `sendline()` to an executable. How can I emulate this functionality in bash? ### Example ```python #whatever.py x = input("First input please: ") y = input("Second input please: ") ``` I know I can `echo "input1" | python3 whate...
So python has a convenient function as part of
pwntools
where one can sendline()
to an executable. How can I emulate this functionality in bash?
### Example
#whatever.py
x = input("First input please: ")
y = input("Second input please: ")
I know I can echo "input1" | python3 whatever.py
to answer the first input, but I can't make it work multiline (echo "input1\ninput2" | ...
doesn't work, and neither does echo "input1"; echo "input2" | ...
).
belkarx
(365 rep)
Apr 30, 2022, 04:47 PM
• Last activity: Jan 14, 2025, 05:17 PM
2
votes
1
answers
3399
views
Prompt for ssh password if needed, then pipe into the ssh session
As an experiment, I'm trying to write a script where I pipe a ZIP file into `unzip` on my server via `ssh`, however, what if I didn't have my SSH keys set up, and was prompted for a password? I'd still like it to come from `stdin`, not from the ZIP file - THEN I want to pipe a ZIP file into `unzip`,...
As an experiment, I'm trying to write a script where I pipe a ZIP file into
unzip
on my server via ssh
, however, what if I didn't have my SSH keys set up, and was prompted for a password? I'd still like it to come from stdin
, not from the ZIP file - THEN I want to pipe a ZIP file into unzip
, once the connection is established (maybe using two separate input pipes, one for the SSH password, one for the unzip
process that ssh
runs?).
Also, I'm currently writing into /tmp
on the server, then deleting, because unzip
doesn't seem to like /dev/stdin
on my server (I'm running Arch, the server is running Ubuntu 20.04). /dev/stdin
works when I pipe inside of the ssh
session, it works when I pipe on my machine, but not when I pipe FROM my machine, into ssh
. Any reason why?
Liran
(21 rep)
Sep 3, 2021, 05:01 AM
• Last activity: Jan 8, 2025, 10:07 PM
7
votes
3
answers
6621
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 `test.tar` file with the contents `dev/stdin`. The `stdin` file is a link to `/proc/self/fd/0`. What I w...
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
test.tar
file with the contents dev/stdin
. The stdin
file is a link to /proc/self/fd/0
.
What I want instead is for dev/stdin
inside the TAR file to be a regular file with the text test
inside. A similar thing happens with:
$ tar -cf test.tar <(echo test)
but the names are different.
Is this doable?
Daffy
(465 rep)
Aug 5, 2018, 01:52 AM
• Last activity: Nov 22, 2024, 10:23 AM
130
votes
8
answers
303478
views
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=$(</dev/stdin) echo foo | myvar=$(cat) echo foo | myvar=$(tee) But `$myvar` is empty. I don’t want to do: myvar=$(echo foo) Because I don’t want to spawn a subshell. Any ideas? **Edit:** I don’t w...
I am trying to get the output of a pipe into a variable. I tried the following things:
echo foo | myvar=$($myvar is empty.
I don’t want to do:
myvar=$(echo foo)
Because I don’t want to spawn a subshell.
Any ideas?
**Edit:** I don’t want to spawn a subshell because the command before the pipe needs to edit global variables, which it can’t do in a subshell. Can it? The
echo
thing is just for simplification. It’s more like:
complex_function | myvar=$(
Parckwart
(1301 rep)
Jan 17, 2017, 10:13 AM
• Last activity: Aug 23, 2024, 08:45 AM
24
votes
3
answers
6353
views
tee stdout to stderr?
I'd like to send stdout from one process to the stdin of another process, but also to the console. Sending stdout to stdout+stderr, for instance. For example, I've got `git edit` aliased to the following: git status --short | cut -b4- | xargs gvim --remote I'd like the list of filenames to be sent t...
I'd like to send stdout from one process to the stdin of another process, but also to the console. Sending stdout to stdout+stderr, for instance.
For example, I've got
git edit
aliased to the following:
git status --short | cut -b4- | xargs gvim --remote
I'd like the list of filenames to be sent to the screen as well as to xargs
.
So, is there a tee
-like utility that'll do this? So that I can do something like:
git status --short | \
cut -b4- | almost-but-not-quite-entirely-unlike-tee | \
xargs gvim --remote
Roger Lipscombe
(1780 rep)
Apr 30, 2014, 09:10 AM
• Last activity: Aug 11, 2024, 09:13 AM
1
votes
1
answers
53
views
How do I ask gnu parallel to preserve stdin?
I'm using GNU parallel like this (:::: is a form of --arg-file): parallel -0Xuj1 my-command -- :::: <(find … -print0) But it seems like the command's standard input is managed by GNU parallel, which doesn't work for an interactive command. The command complains when its stdin gets closed. I'm guessi...
I'm using GNU parallel like this (:::: is a form of --arg-file):
parallel -0Xuj1 my-command -- :::: <(find … -print0)
But it seems like the command's standard input is managed by GNU parallel, which doesn't work for an interactive command. The command complains when its stdin gets closed. I'm guessing GNU parallel wants to use stdin to append to the arg list.
I've been able to use the command interactively with parallel's
--tmux
flag and reattaching, but that's needlessly complicated.
So far my workaround is to use plain xargs. I'm not using find -exec my-command -- {} +
because it builds an argument list that's too large for my-command (it's Python, it reexecs itself and breaks; parallel and xargs have a flag to leave some headroom). Does anyone know a flag to tell GNU parallel to leave stdin alone?
xargs -0a <(find … -print0) my-command --
Tobu
(6769 rep)
Jul 30, 2024, 08:55 AM
• Last activity: Jul 30, 2024, 12:59 PM
3
votes
3
answers
1723
views
When and where are the standard in, out, and error file descriptors first opened in linux?
Where are stdin, stdout, and stderr (the fds) **first** opened? Is it the kernel that does it? And when and where are the symlinks /dev/std{in,out,err} made? Where is the code that does it? I assume it is in the linux kernel source code but I wasn't able to find where it happens even after a search...
Where are stdin, stdout, and stderr (the fds) **first** opened? Is it the kernel that does it? And when and where are the symlinks /dev/std{in,out,err} made? Where is the code that does it?
I assume it is in the linux kernel source code but I wasn't able to find where it happens even after a search in the archlinux 6.5.3-arch1-1 linux kernel github repo.
edit: please, if you are downvoting this question can you explain why so I can make it better? I would really like to know about this question. It is not easy to find the answer.
Elfen Dew
(69 rep)
Sep 22, 2023, 12:31 AM
• Last activity: May 21, 2024, 03:25 AM
0
votes
2
answers
85
views
What does '-' as a file parameter mean?
I'm having trouble finding a name for the `-` character in the context of a piped bash command. 1. What is the `-` character called? 2. Can I replace it with something more readable for a script? Example command: ``` echo -ne "my command" | socat - /dev/somefile ```
I'm having trouble finding a name for the
-
character in the context of a piped bash command.
1. What is the -
character called?
2. Can I replace it with something more readable for a script?
Example command:
echo -ne "my command" | socat - /dev/somefile
tarabyte
(4506 rep)
Apr 26, 2024, 03:22 AM
• Last activity: Apr 26, 2024, 11:10 PM
1
votes
0
answers
237
views
Redirecting fifo to python's stdin
```sh $ mkfifo mypipe $ echo "hello redirection" > mypipe ``` ```sh $ cat mypipe $ echo "hello redirection" > mypipe ``` However if I put python in a loop ```py # pyecho.py while True: with open("/dev/stdin", "r") as f: print(f.read()) ``` Then after the initial iteration (requiring two writes), it...
$ mkfifo mypipe
$ echo "hello redirection" > mypipe
$ cat mypipe
$ echo "hello redirection" > mypipe
However if I put python in a loop
# pyecho.py
while True:
with open("/dev/stdin", "r") as f:
print(f.read())
Then after the initial iteration (requiring two writes), it goes back to working as expected.
Tom Huntington
(109 rep)
Apr 12, 2024, 02:42 AM
• Last activity: Apr 12, 2024, 02:49 AM
0
votes
1
answers
96
views
Archiving stdout to multiple tapes
I have large files which are generated on the fly to stdout, one every 24hours. I would like to archive these files progressively on tapes, ideally in a single archive which potentially spans multiple tapes. Tar is very good for managing the tapes, as it has built-in functionalities to append to an...
I have large files which are generated on the fly to stdout, one every 24hours. I would like to archive these files progressively on tapes, ideally in a single archive which potentially spans multiple tapes.
Tar is very good for managing the tapes, as it has built-in functionalities to append to an archive and to load the next tape. But it is very poor at accepting data from stdin. No matter what I do, it ends up writing a special file (link or named pipe) to the archive, instead of its content.
Here is the example command, that I have been trying. The first day, generate a new archive:
ln -s /dev/stdin day1 # or use the --transform option of tar
data_generator | tar -c -h -M -f /dev/nst0 -H posix -F 'mtx -f /dev/sch0 next' day1
the next day, I would like to just change -c to -A and save the new stream into a new file appended to the tar archive, loading a new tape when it becomes necessary.
data_generator | tar -A -h -M -f /dev/nst0 -H posix -F 'mtx -f /dev/sch0 next' day2
As I said, all I find in the archive is a named pipe (with -h) or a symlink (without -h).
Some ideas that I have tried and are not good:
1. Using split
instead of tar
is not viable, because it is too basic. It can only split to pre-defined dimension (not good if I do not start from the beginning of the tape), and it cannot concatenate the different days in an unpackable archive. Tar does not need to know the size of the data nor the tape, it will just switch to a new tape when it gets a write error.
2. I've read the manuals of cpio, star and dar. I do not get the impression that they cope with pipes better than tar.
Thank you for any hints.
Edit: I'm starting to think that it is impossible with tar, because it needs to know the size of the file before starting to write. In fact, an archive that can be expanded, appending is very tricky if you do write the size before the content.
lorenzo
(1 rep)
Mar 1, 2024, 09:13 PM
• Last activity: Mar 5, 2024, 04:55 PM
0
votes
1
answers
95
views
Script that reads input from terminal. How to tell the script to print to both tty and stdout in case it is called with a stdout redirection?
I have a script which asks users for input in the terminal, therefore in case the script is called with stdout redirected to a file, the user has no context on the prompt. So I would like to duplicate stdout to both sites. The script outputs a calculus so it still makes sense to allow stdout redirec...
I have a script which asks users for input in the terminal, therefore in case the script is called with stdout redirected to a file, the user has no context on the prompt. So I would like to duplicate stdout to both sites.
The script outputs a calculus so it still makes sense to allow stdout redirection.
But if stdin is provided (kind of yes command or non-interactive context like a cron), it makes sense the output IS perfectly allowed to not being required in the tty.
So I would like to do some kind of logic like:
If (test -t 0 && ! test -t 1);
// Tell stdout to print everything to tty as well
Is this possible? Or is it fundamentally inappropriate?
Whimusical
(285 rep)
Feb 24, 2024, 06:52 PM
• Last activity: Feb 26, 2024, 01:39 PM
0
votes
1
answers
154
views
How to identify what file descriptors are associated to STDIN, STDOUT etc
I seem to remember some command or envvar that tells you this. I'd like basically something that executed on terminal, for instance, give you echo $STDIN /dev/tty echo $STDOUT /dev/tty fdescribe 0 or fdescribe /dev/stdin /dev/tty fdescribe 1 or fdescribe /dev/stdout /dev/tty but that can be executed...
I seem to remember some command or envvar that tells you this.
I'd like basically something that executed on terminal, for instance, give you
echo $STDIN
/dev/tty
echo $STDOUT
/dev/tty
fdescribe 0 or fdescribe /dev/stdin
/dev/tty
fdescribe 1 or fdescribe /dev/stdout
/dev/tty
but that can be executed in a script or subprocess
Whimusical
(285 rep)
Feb 24, 2024, 05:41 PM
• Last activity: Feb 24, 2024, 07:42 PM
0
votes
1
answers
113
views
Standard input stream redirection
`stdin`: Generally standard input, referred to as `stdin`, comes from the keyboard. When you type stuff, you're typing it on `stdin` (a standard input terminal). A standard input device, which is usually the keyboard, but Linux also allows you take standard input from a file. For example: ```lang-sh...
stdin
: Generally standard input, referred to as stdin
, comes from the keyboard.
When you type stuff, you're typing it on stdin
(a standard input terminal). A standard input device, which is usually the keyboard, but Linux also allows you take standard input from a file.
For example:
-shell
cat < myfirstscript
This would tell cat
to take input from the file myfirstscript
instead of from the keyboard (This is of course the same as: cat myfirstscript
).
Essentially what this boils down to is that the input for this command (cat
) is no longer coming from where it was expecting to come from (the keyboard), but is now coming from a file.
I'm confusing something: it was expecting to come from (the keyboard), but is now coming from a file.
When you type a file on the keyboard (like: cat myfirstscript
) isn't this a file in the same way?
Guilherme Woolley
(1 rep)
Feb 14, 2024, 08:36 PM
• Last activity: Feb 23, 2024, 03:58 PM
0
votes
0
answers
472
views
read single line from stdin and write to a file
Is there a way in bash to read a single line from stdin and write directly to a file? Something like: t="$(mktemp)" while true do [read single line from stdin] > "${t}" [nothing to read] && break printf '%s\n' "$t" t="$(mktemp)" done I have limited RAM available and expect lines that could be absurd...
Is there a way in bash to read a single line from stdin and write directly to a file? Something like:
t="$(mktemp)"
while true
do
[read single line from stdin] > "${t}"
[nothing to read] && break
printf '%s\n' "$t"
t="$(mktemp)"
done
I have limited RAM available and expect lines that could be absurdly long. Otherwise I'd just do a while-read loop.
Edit:
I need to do some extractions and filtering. A more complete pseudo code-ish snippet would be something like:
f () {
t="$(mktemp)"
while true
do
[read single line from stdin] > "${t}"
[nothing to read] && break
printf '%s\n' "$t"
t="$(mktemp)"
done | while read -r file
do
if cat "$file" | grep -q '[criteria]'
then
cat "$file" | jq '[filter1]'
cat "$file" | jq '[filter2]' >> [seprate file]
[etc]
else
printf '%s\n' "There was a mismatch" > /dev/stderr
fi
rm "$file"
done
}
fuumind
(449 rep)
Jan 25, 2024, 02:28 PM
• Last activity: Jan 25, 2024, 04:34 PM
0
votes
1
answers
57
views
saving xargs ouput from multi files to one file
I have these three text files : ``` #1.txt hey stackoverflow ``` ``` #2.txt hey stackexchange ``` ``` #3.txt hello world ``` I am using this command to list the last 3 files in my dir and then `cat` them and then save all the output from 3 files to one file (`all.txt`) Command : ``` ls -alth *txt |...
I have these three text files :
#1.txt
hey stackoverflow
#2.txt
hey stackexchange
#3.txt
hello world
I am using this command to list the last 3 files in my dir and then cat
them and then save all the output from 3 files to one file (all.txt
)
Command :
ls -alth *txt | head -3 | xargs -n1 cat
How I can redirect the output to a file ??
Anonymous101
(3 rep)
Jan 17, 2024, 12:09 PM
• Last activity: Jan 17, 2024, 01:16 PM
0
votes
1
answers
103
views
Quote characters work as commands that redirect to the standard input
I am a student and I am trying an excercise that involves assigning a word with quotes, double quotes and other symbols to a file name. The problem is that I am not getting the expected results. I am using the scape bar to scape the symbols, but when I list the name of the file this appears with une...
I am a student and I am trying an excercise that involves assigning a word with quotes, double quotes and other symbols to a file name.
The problem is that I am not getting the expected results.
I am using the scape bar to scape the symbols, but when I list the name of the file this appears with unexpected single quotes at the beginning and the end of the file name and scape bars surrounded by single quotes before the single quotes that are supposed to be part of the file name. This is a bit confusing, I'll show you: $ echo > \"\\\?\$\*\'\'\*\$\?\\\" I expect this: $ ls "\?$*''*$?\" but I get this instead: $ ls '"\?$*'\'''\''*$?\"' I've tried to do it in other ways such as wrapping the double quotes in single quotes and viceversa, but I always get the same result. I already had made the same excercise in other computer and it worked perfectly. What is more intriguing is that I've discovered that both the single and the double quote work as a command to redirect to the standard input, what, I suspect, has to do with the unexpected name display: $ ' > $ " > The commands don't seem to work for anything else than to display the standard input. Is this normal at all? What is going on? What can I do?
I am using the scape bar to scape the symbols, but when I list the name of the file this appears with unexpected single quotes at the beginning and the end of the file name and scape bars surrounded by single quotes before the single quotes that are supposed to be part of the file name. This is a bit confusing, I'll show you: $ echo > \"\\\?\$\*\'\'\*\$\?\\\" I expect this: $ ls "\?$*''*$?\" but I get this instead: $ ls '"\?$*'\'''\''*$?\"' I've tried to do it in other ways such as wrapping the double quotes in single quotes and viceversa, but I always get the same result. I already had made the same excercise in other computer and it worked perfectly. What is more intriguing is that I've discovered that both the single and the double quote work as a command to redirect to the standard input, what, I suspect, has to do with the unexpected name display: $ ' > $ " > The commands don't seem to work for anything else than to display the standard input. Is this normal at all? What is going on? What can I do?
Daniel
(11 rep)
Dec 15, 2023, 09:33 PM
• Last activity: Dec 19, 2023, 11:08 PM
3
votes
2
answers
2146
views
Duplicate stdin to stdout and stderr, but in a synchronized way
I need to duplicate the stdout of a producer and feed it to two consumer in a **synchronized** fashion. consumer 1 producer | duplicator | consumer 2 This can easily be accomplished for example via `tee`: ```bash ((cat f.txt | tee /dev/stderr | ./cons1.py >&3) 2>&1 | ./cons2.py) 3>&1 ``` or via name...
I need to duplicate the stdout of a producer and feed it to two consumer in a **synchronized** fashion.
consumer 1
producer | duplicator |
consumer 2
This can easily be accomplished for example via
tee
:
((cat f.txt | tee /dev/stderr | ./cons1.py >&3) 2>&1 | ./cons2.py) 3>&1
or via named pipes:
mkfifo fifo1 fifo2
cat f.txt | tee fifo1 fifo2 >/dev/null &
int main()
{
char *line = NULL;
size_t size;
while (getline(&line, &size, stdin) != -1) {
fprintf(stdout, "%s", line);
fprintf(stderr, "%s", line);
}
return 0;
}
and then:
((cat f.txt | ./dup | ./cons1.py >&3) 2>&1 | ./cons2.py) 3>&1
However, **if consumer 1 is faster than consumer 2 we have a problem**. E.g., consumer 1 is already at line 50,000 while consumer 2 is at line 17,000.
For my system **I need that both consumers are at the same line, hence the faster consumer needs to be restricted**. I know that this might be impossible via Linux standard tools. However, at least if we use that dup.c
approach, it should be somehow possible. Any suggestions how to accomplish this? Thanks!
m33x
(33 rep)
Sep 6, 2015, 12:06 PM
• Last activity: Dec 14, 2023, 06:31 PM
Showing page 1 of 20 total questions