Watching something be piped to a file live with tailHow to continue running a program inspite of killing the...
Is there a hemisphere-neutral way of specifying a season?
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
Unlock My Phone! February 2018
What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"
Reverse dictionary where values are lists
Why no variance term in Bayesian logistic regression?
CAST throwing error when run in stored procedure but not when run as raw query
Which is the best way to check return result?
How could indestructible materials be used in power generation?
What do you call someone who asks many questions?
Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?
Do UK voters know if their MP will be the Speaker of the House?
Why do bosons tend to occupy the same state?
Ambiguity in the definition of entropy
Am I breaking OOP practice with this architecture?
Size of subfigure fitting its content (tikzpicture)
How can I determine if the org that I'm currently connected to is a scratch org?
How do I handle a potential work/personal life conflict as the manager of one of my friends?
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
Examples of smooth manifolds admitting inbetween one and a continuum of complex structures
A category-like structure without composition?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?
Is "remove commented out code" correct English?
Watching something be piped to a file live with tail
How to continue running a program inspite of killing the shell which invoked itLinux terminal, my program only resumes after scrolling the printoutIs there a command in Linux which waits till it will be terminated?Ctrl+c in a sub process is killing a nohup'ed process earlier in the scriptCtrl-C'd an in-place recursive gzip - is this likely to have broken anything?Getting output of another script while preserving line-breakssocat and rich terminal againScript executed as other user from root creates files in wrong directory (root)Dealing with Ctrl+Z in UnixHow to pass Ctrl+C to script called from batch job
I have a python program which is, slowly, generating some output.
I want to capture that in a file, but I also thought I could watch it live with tail.
So in one terminal I'm doing :
python myprog.py > output.txt
and in another terminal :
tail -f output.txt
But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.
What am I doing wrong?
linux command-line pipe
add a comment |
I have a python program which is, slowly, generating some output.
I want to capture that in a file, but I also thought I could watch it live with tail.
So in one terminal I'm doing :
python myprog.py > output.txt
and in another terminal :
tail -f output.txt
But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.
What am I doing wrong?
linux command-line pipe
2
How aboutpython myprog.py | tee output.txt
instead?
– n8te
2 hours ago
add a comment |
I have a python program which is, slowly, generating some output.
I want to capture that in a file, but I also thought I could watch it live with tail.
So in one terminal I'm doing :
python myprog.py > output.txt
and in another terminal :
tail -f output.txt
But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.
What am I doing wrong?
linux command-line pipe
I have a python program which is, slowly, generating some output.
I want to capture that in a file, but I also thought I could watch it live with tail.
So in one terminal I'm doing :
python myprog.py > output.txt
and in another terminal :
tail -f output.txt
But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.
What am I doing wrong?
linux command-line pipe
linux command-line pipe
asked 2 hours ago
interstarinterstar
320310
320310
2
How aboutpython myprog.py | tee output.txt
instead?
– n8te
2 hours ago
add a comment |
2
How aboutpython myprog.py | tee output.txt
instead?
– n8te
2 hours ago
2
2
How about
python myprog.py | tee output.txt
instead?– n8te
2 hours ago
How about
python myprog.py | tee output.txt
instead?– n8te
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.
import sys
...
print('Some message')
sys.stdout.flush()
New contributor
add a comment |
Instead of trying to tail a live file, use tee
instead. It was made to do exactly what you're trying to do.
From man tee:
tee(1) - Linux man page
Name tee - read from standard input and write to standard output and files
Synopsis
tee [OPTION]... [FILE]...
Description
Copy standard input to each FILE, and also to standard output.
-a, --append
append to the given FILEs, do not overwrite
-i, --ignore-interrupts
ignore interrupt signals
--help
display this help and exit
--version
output version information and exit
If a FILE is -, copy again to standard output.
So in your case you'd run:
python myprog.py | tee output.txt
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%2f1421123%2fwatching-something-be-piped-to-a-file-live-with-tail%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.
import sys
...
print('Some message')
sys.stdout.flush()
New contributor
add a comment |
You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.
import sys
...
print('Some message')
sys.stdout.flush()
New contributor
add a comment |
You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.
import sys
...
print('Some message')
sys.stdout.flush()
New contributor
You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.
import sys
...
print('Some message')
sys.stdout.flush()
New contributor
New contributor
answered 2 hours ago
DaveyDavey
361
361
New contributor
New contributor
add a comment |
add a comment |
Instead of trying to tail a live file, use tee
instead. It was made to do exactly what you're trying to do.
From man tee:
tee(1) - Linux man page
Name tee - read from standard input and write to standard output and files
Synopsis
tee [OPTION]... [FILE]...
Description
Copy standard input to each FILE, and also to standard output.
-a, --append
append to the given FILEs, do not overwrite
-i, --ignore-interrupts
ignore interrupt signals
--help
display this help and exit
--version
output version information and exit
If a FILE is -, copy again to standard output.
So in your case you'd run:
python myprog.py | tee output.txt
add a comment |
Instead of trying to tail a live file, use tee
instead. It was made to do exactly what you're trying to do.
From man tee:
tee(1) - Linux man page
Name tee - read from standard input and write to standard output and files
Synopsis
tee [OPTION]... [FILE]...
Description
Copy standard input to each FILE, and also to standard output.
-a, --append
append to the given FILEs, do not overwrite
-i, --ignore-interrupts
ignore interrupt signals
--help
display this help and exit
--version
output version information and exit
If a FILE is -, copy again to standard output.
So in your case you'd run:
python myprog.py | tee output.txt
add a comment |
Instead of trying to tail a live file, use tee
instead. It was made to do exactly what you're trying to do.
From man tee:
tee(1) - Linux man page
Name tee - read from standard input and write to standard output and files
Synopsis
tee [OPTION]... [FILE]...
Description
Copy standard input to each FILE, and also to standard output.
-a, --append
append to the given FILEs, do not overwrite
-i, --ignore-interrupts
ignore interrupt signals
--help
display this help and exit
--version
output version information and exit
If a FILE is -, copy again to standard output.
So in your case you'd run:
python myprog.py | tee output.txt
Instead of trying to tail a live file, use tee
instead. It was made to do exactly what you're trying to do.
From man tee:
tee(1) - Linux man page
Name tee - read from standard input and write to standard output and files
Synopsis
tee [OPTION]... [FILE]...
Description
Copy standard input to each FILE, and also to standard output.
-a, --append
append to the given FILEs, do not overwrite
-i, --ignore-interrupts
ignore interrupt signals
--help
display this help and exit
--version
output version information and exit
If a FILE is -, copy again to standard output.
So in your case you'd run:
python myprog.py | tee output.txt
answered 2 hours ago
n8ten8te
5,16172234
5,16172234
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%2f1421123%2fwatching-something-be-piped-to-a-file-live-with-tail%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
2
How about
python myprog.py | tee output.txt
instead?– n8te
2 hours ago