How to reference stdin as an option in a program in a pipeline?
I have a program that outputs a file that I want to use as stdin for the next program. However, program2 has "-in" and "-out" options that want filenames. So if I'm piping into program2, how can I reference the stdin for the "-in" option?
program1 | program2 -in stdin -out filename
bash stdin
add a comment |
I have a program that outputs a file that I want to use as stdin for the next program. However, program2 has "-in" and "-out" options that want filenames. So if I'm piping into program2, how can I reference the stdin for the "-in" option?
program1 | program2 -in stdin -out filename
bash stdin
add a comment |
I have a program that outputs a file that I want to use as stdin for the next program. However, program2 has "-in" and "-out" options that want filenames. So if I'm piping into program2, how can I reference the stdin for the "-in" option?
program1 | program2 -in stdin -out filename
bash stdin
I have a program that outputs a file that I want to use as stdin for the next program. However, program2 has "-in" and "-out" options that want filenames. So if I'm piping into program2, how can I reference the stdin for the "-in" option?
program1 | program2 -in stdin -out filename
bash stdin
bash stdin
asked Jan 7 at 19:01
MichaelMichael
1
1
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
If program2
doesn't use its stdin by itself and -in
is the only way to specify the input file, these are useful options:
/proc/self/fd/0
or/proc/fd/0
(if available; kernel feature, not required by POSIX)
program1 | program2 -in /proc/self/fd/0 -out filename
Process substitution (supported in Bash and few other shells, not required by POSIX)
program2 -in <(program1) -out filename
Named fifo (POSIX way)
mkfifo foo
program1 >foo & # in background
program2 -in foo -out filename
rm fifo
Note that many programs that don't normally use their stdin, behave this way for a reason: they need the input file to be seekable. With <bar program2
you can make the file descriptor 0 of program2
point to the bar
file which is seekable, but in general stdin is not seekable, so such programs don't bother using it. Each of the above methods may make your program fail if it expects the file to be seekable.
1
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
add a comment |
You can do something like
program1 > stdin & program2 -in stdin -out filename
This is not a pipe actually but will put all the stdout of program1 inside stdin file so then program2 can read it.
Alternatively some programs use the shorthand - when they attempt to read/write from shell. So it may be like:
program1 | program2 -in - -out filename
add a comment |
The following syntax should work in shell by pointing input file to a special file /dev/stdin
:
program1 | program2 -in /dev/stdin -out filename
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391610%2fhow-to-reference-stdin-as-an-option-in-a-program-in-a-pipeline%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If program2
doesn't use its stdin by itself and -in
is the only way to specify the input file, these are useful options:
/proc/self/fd/0
or/proc/fd/0
(if available; kernel feature, not required by POSIX)
program1 | program2 -in /proc/self/fd/0 -out filename
Process substitution (supported in Bash and few other shells, not required by POSIX)
program2 -in <(program1) -out filename
Named fifo (POSIX way)
mkfifo foo
program1 >foo & # in background
program2 -in foo -out filename
rm fifo
Note that many programs that don't normally use their stdin, behave this way for a reason: they need the input file to be seekable. With <bar program2
you can make the file descriptor 0 of program2
point to the bar
file which is seekable, but in general stdin is not seekable, so such programs don't bother using it. Each of the above methods may make your program fail if it expects the file to be seekable.
1
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
add a comment |
If program2
doesn't use its stdin by itself and -in
is the only way to specify the input file, these are useful options:
/proc/self/fd/0
or/proc/fd/0
(if available; kernel feature, not required by POSIX)
program1 | program2 -in /proc/self/fd/0 -out filename
Process substitution (supported in Bash and few other shells, not required by POSIX)
program2 -in <(program1) -out filename
Named fifo (POSIX way)
mkfifo foo
program1 >foo & # in background
program2 -in foo -out filename
rm fifo
Note that many programs that don't normally use their stdin, behave this way for a reason: they need the input file to be seekable. With <bar program2
you can make the file descriptor 0 of program2
point to the bar
file which is seekable, but in general stdin is not seekable, so such programs don't bother using it. Each of the above methods may make your program fail if it expects the file to be seekable.
1
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
add a comment |
If program2
doesn't use its stdin by itself and -in
is the only way to specify the input file, these are useful options:
/proc/self/fd/0
or/proc/fd/0
(if available; kernel feature, not required by POSIX)
program1 | program2 -in /proc/self/fd/0 -out filename
Process substitution (supported in Bash and few other shells, not required by POSIX)
program2 -in <(program1) -out filename
Named fifo (POSIX way)
mkfifo foo
program1 >foo & # in background
program2 -in foo -out filename
rm fifo
Note that many programs that don't normally use their stdin, behave this way for a reason: they need the input file to be seekable. With <bar program2
you can make the file descriptor 0 of program2
point to the bar
file which is seekable, but in general stdin is not seekable, so such programs don't bother using it. Each of the above methods may make your program fail if it expects the file to be seekable.
If program2
doesn't use its stdin by itself and -in
is the only way to specify the input file, these are useful options:
/proc/self/fd/0
or/proc/fd/0
(if available; kernel feature, not required by POSIX)
program1 | program2 -in /proc/self/fd/0 -out filename
Process substitution (supported in Bash and few other shells, not required by POSIX)
program2 -in <(program1) -out filename
Named fifo (POSIX way)
mkfifo foo
program1 >foo & # in background
program2 -in foo -out filename
rm fifo
Note that many programs that don't normally use their stdin, behave this way for a reason: they need the input file to be seekable. With <bar program2
you can make the file descriptor 0 of program2
point to the bar
file which is seekable, but in general stdin is not seekable, so such programs don't bother using it. Each of the above methods may make your program fail if it expects the file to be seekable.
edited Jan 7 at 20:34
answered Jan 7 at 20:27
Kamil MaciorowskiKamil Maciorowski
27.2k155982
27.2k155982
1
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
add a comment |
1
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
1
1
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
I'd recommend /dev/stdin instead of /proc/[self]/fd/0 -- it's not required by POSIX either, but it seems to be much more widely supported than /proc. See here and here.
– Gordon Davisson
Jan 7 at 22:42
add a comment |
You can do something like
program1 > stdin & program2 -in stdin -out filename
This is not a pipe actually but will put all the stdout of program1 inside stdin file so then program2 can read it.
Alternatively some programs use the shorthand - when they attempt to read/write from shell. So it may be like:
program1 | program2 -in - -out filename
add a comment |
You can do something like
program1 > stdin & program2 -in stdin -out filename
This is not a pipe actually but will put all the stdout of program1 inside stdin file so then program2 can read it.
Alternatively some programs use the shorthand - when they attempt to read/write from shell. So it may be like:
program1 | program2 -in - -out filename
add a comment |
You can do something like
program1 > stdin & program2 -in stdin -out filename
This is not a pipe actually but will put all the stdout of program1 inside stdin file so then program2 can read it.
Alternatively some programs use the shorthand - when they attempt to read/write from shell. So it may be like:
program1 | program2 -in - -out filename
You can do something like
program1 > stdin & program2 -in stdin -out filename
This is not a pipe actually but will put all the stdout of program1 inside stdin file so then program2 can read it.
Alternatively some programs use the shorthand - when they attempt to read/write from shell. So it may be like:
program1 | program2 -in - -out filename
answered Jan 7 at 20:04
user1330614user1330614
1334
1334
add a comment |
add a comment |
The following syntax should work in shell by pointing input file to a special file /dev/stdin
:
program1 | program2 -in /dev/stdin -out filename
add a comment |
The following syntax should work in shell by pointing input file to a special file /dev/stdin
:
program1 | program2 -in /dev/stdin -out filename
add a comment |
The following syntax should work in shell by pointing input file to a special file /dev/stdin
:
program1 | program2 -in /dev/stdin -out filename
The following syntax should work in shell by pointing input file to a special file /dev/stdin
:
program1 | program2 -in /dev/stdin -out filename
answered Jan 7 at 20:57
kenorbkenorb
11.1k1578115
11.1k1578115
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391610%2fhow-to-reference-stdin-as-an-option-in-a-program-in-a-pipeline%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown