How to capture a changing one line program output?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












A program outputs various data lines to the same line in a timely order, overwriting the line in each line write. How can I capture all of its output lines and write them to a file separated by newlines?
Regular redirection would not do it.







share|improve this question






















  • Regular redirection would not do it. Have you tried? The data will be in the file anyway.
    – Andrew Henle
    Apr 10 at 14:55











  • Yes I have tried. The program removes all of its output in the end and so even if something could have been written it would still get overwritten with blank.
    – elig
    Apr 10 at 15:13










  • The program removes all of its output in the end How do you know? Did you simply redirect output to a file, then cat that file?
    – Andrew Henle
    Apr 10 at 15:17










  • No. I watched it in my terminal. It displays a few lines replaced going on for a few seconds and then it erases back to the start and a bash prompt reappears in the beginning of the line like the program never ran.
    – elig
    Apr 10 at 15:18











  • No. I watched it in my terminal. So, you've never actually tried redirection? That means you don't really know whether or not redirection actually works.
    – Andrew Henle
    Apr 10 at 15:20














up vote
0
down vote

favorite












A program outputs various data lines to the same line in a timely order, overwriting the line in each line write. How can I capture all of its output lines and write them to a file separated by newlines?
Regular redirection would not do it.







share|improve this question






















  • Regular redirection would not do it. Have you tried? The data will be in the file anyway.
    – Andrew Henle
    Apr 10 at 14:55











  • Yes I have tried. The program removes all of its output in the end and so even if something could have been written it would still get overwritten with blank.
    – elig
    Apr 10 at 15:13










  • The program removes all of its output in the end How do you know? Did you simply redirect output to a file, then cat that file?
    – Andrew Henle
    Apr 10 at 15:17










  • No. I watched it in my terminal. It displays a few lines replaced going on for a few seconds and then it erases back to the start and a bash prompt reappears in the beginning of the line like the program never ran.
    – elig
    Apr 10 at 15:18











  • No. I watched it in my terminal. So, you've never actually tried redirection? That means you don't really know whether or not redirection actually works.
    – Andrew Henle
    Apr 10 at 15:20












up vote
0
down vote

favorite









up vote
0
down vote

favorite











A program outputs various data lines to the same line in a timely order, overwriting the line in each line write. How can I capture all of its output lines and write them to a file separated by newlines?
Regular redirection would not do it.







share|improve this question














A program outputs various data lines to the same line in a timely order, overwriting the line in each line write. How can I capture all of its output lines and write them to a file separated by newlines?
Regular redirection would not do it.









share|improve this question













share|improve this question




share|improve this question








edited Apr 10 at 15:25









Stephen Kitt

140k22305365




140k22305365










asked Apr 10 at 14:50









elig

215




215











  • Regular redirection would not do it. Have you tried? The data will be in the file anyway.
    – Andrew Henle
    Apr 10 at 14:55











  • Yes I have tried. The program removes all of its output in the end and so even if something could have been written it would still get overwritten with blank.
    – elig
    Apr 10 at 15:13










  • The program removes all of its output in the end How do you know? Did you simply redirect output to a file, then cat that file?
    – Andrew Henle
    Apr 10 at 15:17










  • No. I watched it in my terminal. It displays a few lines replaced going on for a few seconds and then it erases back to the start and a bash prompt reappears in the beginning of the line like the program never ran.
    – elig
    Apr 10 at 15:18











  • No. I watched it in my terminal. So, you've never actually tried redirection? That means you don't really know whether or not redirection actually works.
    – Andrew Henle
    Apr 10 at 15:20
















  • Regular redirection would not do it. Have you tried? The data will be in the file anyway.
    – Andrew Henle
    Apr 10 at 14:55











  • Yes I have tried. The program removes all of its output in the end and so even if something could have been written it would still get overwritten with blank.
    – elig
    Apr 10 at 15:13










  • The program removes all of its output in the end How do you know? Did you simply redirect output to a file, then cat that file?
    – Andrew Henle
    Apr 10 at 15:17










  • No. I watched it in my terminal. It displays a few lines replaced going on for a few seconds and then it erases back to the start and a bash prompt reappears in the beginning of the line like the program never ran.
    – elig
    Apr 10 at 15:18











  • No. I watched it in my terminal. So, you've never actually tried redirection? That means you don't really know whether or not redirection actually works.
    – Andrew Henle
    Apr 10 at 15:20















Regular redirection would not do it. Have you tried? The data will be in the file anyway.
– Andrew Henle
Apr 10 at 14:55





Regular redirection would not do it. Have you tried? The data will be in the file anyway.
– Andrew Henle
Apr 10 at 14:55













Yes I have tried. The program removes all of its output in the end and so even if something could have been written it would still get overwritten with blank.
– elig
Apr 10 at 15:13




Yes I have tried. The program removes all of its output in the end and so even if something could have been written it would still get overwritten with blank.
– elig
Apr 10 at 15:13












The program removes all of its output in the end How do you know? Did you simply redirect output to a file, then cat that file?
– Andrew Henle
Apr 10 at 15:17




The program removes all of its output in the end How do you know? Did you simply redirect output to a file, then cat that file?
– Andrew Henle
Apr 10 at 15:17












No. I watched it in my terminal. It displays a few lines replaced going on for a few seconds and then it erases back to the start and a bash prompt reappears in the beginning of the line like the program never ran.
– elig
Apr 10 at 15:18





No. I watched it in my terminal. It displays a few lines replaced going on for a few seconds and then it erases back to the start and a bash prompt reappears in the beginning of the line like the program never ran.
– elig
Apr 10 at 15:18













No. I watched it in my terminal. So, you've never actually tried redirection? That means you don't really know whether or not redirection actually works.
– Andrew Henle
Apr 10 at 15:20




No. I watched it in my terminal. So, you've never actually tried redirection? That means you don't really know whether or not redirection actually works.
– Andrew Henle
Apr 10 at 15:20










1 Answer
1






active

oldest

votes

















up vote
2
down vote













Assuming this is done using r, which returns the cursor to the beginning of the current line without moving to the next line, and that the program in question is sending its output to its standard output, converting all the r characters in the program’s output to n will produce the result you’re after:



yourprogram | tr 'r' 'n' > logfile


See the difference between



printf "Hellorworldn"


and



printf "Hellorworldn" | tr 'r' 'n'


Note that without this, redirecting to a log file will store all the output in the file; you’d be able to see it by viewing the file using less rather than cat. (less will show r as ^M, without overwriting the previous line.)



If the program is writing directly to the terminal, this won’t help. In that case, you’ll need to use a program capable of capturing all the terminal output too; one example is script:



script -c yourprogram logfile


will start the program and capture all its output to logfile. You’ll need to process the special characters in the logfile to make sense of it — less will help you there (or any reasonable editor).






share|improve this answer






















  • Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
    – elig
    Apr 10 at 15:16










  • It occurred to me that this might be an issue — see my update.
    – Stephen Kitt
    Apr 10 at 15:19










  • Wait — do you want to see the output while it’s being logged?
    – Stephen Kitt
    Apr 10 at 15:20










  • i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
    – elig
    Apr 10 at 15:23










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436794%2fhow-to-capture-a-changing-one-line-program-output%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













Assuming this is done using r, which returns the cursor to the beginning of the current line without moving to the next line, and that the program in question is sending its output to its standard output, converting all the r characters in the program’s output to n will produce the result you’re after:



yourprogram | tr 'r' 'n' > logfile


See the difference between



printf "Hellorworldn"


and



printf "Hellorworldn" | tr 'r' 'n'


Note that without this, redirecting to a log file will store all the output in the file; you’d be able to see it by viewing the file using less rather than cat. (less will show r as ^M, without overwriting the previous line.)



If the program is writing directly to the terminal, this won’t help. In that case, you’ll need to use a program capable of capturing all the terminal output too; one example is script:



script -c yourprogram logfile


will start the program and capture all its output to logfile. You’ll need to process the special characters in the logfile to make sense of it — less will help you there (or any reasonable editor).






share|improve this answer






















  • Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
    – elig
    Apr 10 at 15:16










  • It occurred to me that this might be an issue — see my update.
    – Stephen Kitt
    Apr 10 at 15:19










  • Wait — do you want to see the output while it’s being logged?
    – Stephen Kitt
    Apr 10 at 15:20










  • i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
    – elig
    Apr 10 at 15:23














up vote
2
down vote













Assuming this is done using r, which returns the cursor to the beginning of the current line without moving to the next line, and that the program in question is sending its output to its standard output, converting all the r characters in the program’s output to n will produce the result you’re after:



yourprogram | tr 'r' 'n' > logfile


See the difference between



printf "Hellorworldn"


and



printf "Hellorworldn" | tr 'r' 'n'


Note that without this, redirecting to a log file will store all the output in the file; you’d be able to see it by viewing the file using less rather than cat. (less will show r as ^M, without overwriting the previous line.)



If the program is writing directly to the terminal, this won’t help. In that case, you’ll need to use a program capable of capturing all the terminal output too; one example is script:



script -c yourprogram logfile


will start the program and capture all its output to logfile. You’ll need to process the special characters in the logfile to make sense of it — less will help you there (or any reasonable editor).






share|improve this answer






















  • Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
    – elig
    Apr 10 at 15:16










  • It occurred to me that this might be an issue — see my update.
    – Stephen Kitt
    Apr 10 at 15:19










  • Wait — do you want to see the output while it’s being logged?
    – Stephen Kitt
    Apr 10 at 15:20










  • i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
    – elig
    Apr 10 at 15:23












up vote
2
down vote










up vote
2
down vote









Assuming this is done using r, which returns the cursor to the beginning of the current line without moving to the next line, and that the program in question is sending its output to its standard output, converting all the r characters in the program’s output to n will produce the result you’re after:



yourprogram | tr 'r' 'n' > logfile


See the difference between



printf "Hellorworldn"


and



printf "Hellorworldn" | tr 'r' 'n'


Note that without this, redirecting to a log file will store all the output in the file; you’d be able to see it by viewing the file using less rather than cat. (less will show r as ^M, without overwriting the previous line.)



If the program is writing directly to the terminal, this won’t help. In that case, you’ll need to use a program capable of capturing all the terminal output too; one example is script:



script -c yourprogram logfile


will start the program and capture all its output to logfile. You’ll need to process the special characters in the logfile to make sense of it — less will help you there (or any reasonable editor).






share|improve this answer














Assuming this is done using r, which returns the cursor to the beginning of the current line without moving to the next line, and that the program in question is sending its output to its standard output, converting all the r characters in the program’s output to n will produce the result you’re after:



yourprogram | tr 'r' 'n' > logfile


See the difference between



printf "Hellorworldn"


and



printf "Hellorworldn" | tr 'r' 'n'


Note that without this, redirecting to a log file will store all the output in the file; you’d be able to see it by viewing the file using less rather than cat. (less will show r as ^M, without overwriting the previous line.)



If the program is writing directly to the terminal, this won’t help. In that case, you’ll need to use a program capable of capturing all the terminal output too; one example is script:



script -c yourprogram logfile


will start the program and capture all its output to logfile. You’ll need to process the special characters in the logfile to make sense of it — less will help you there (or any reasonable editor).







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 10 at 15:16

























answered Apr 10 at 14:54









Stephen Kitt

140k22305365




140k22305365











  • Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
    – elig
    Apr 10 at 15:16










  • It occurred to me that this might be an issue — see my update.
    – Stephen Kitt
    Apr 10 at 15:19










  • Wait — do you want to see the output while it’s being logged?
    – Stephen Kitt
    Apr 10 at 15:20










  • i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
    – elig
    Apr 10 at 15:23
















  • Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
    – elig
    Apr 10 at 15:16










  • It occurred to me that this might be an issue — see my update.
    – Stephen Kitt
    Apr 10 at 15:19










  • Wait — do you want to see the output while it’s being logged?
    – Stephen Kitt
    Apr 10 at 15:20










  • i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
    – elig
    Apr 10 at 15:23















Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
– elig
Apr 10 at 15:16




Unfortunately, this does not work. Running the first command without redirection it eliminates the output to stdout at all. And with redirection the file gets empty.
– elig
Apr 10 at 15:16












It occurred to me that this might be an issue — see my update.
– Stephen Kitt
Apr 10 at 15:19




It occurred to me that this might be an issue — see my update.
– Stephen Kitt
Apr 10 at 15:19












Wait — do you want to see the output while it’s being logged?
– Stephen Kitt
Apr 10 at 15:20




Wait — do you want to see the output while it’s being logged?
– Stephen Kitt
Apr 10 at 15:20












i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
– elig
Apr 10 at 15:23




i don't mind. I use WSL so I cannot use script. See: superuser.com/questions/1249475/…
– elig
Apr 10 at 15:23












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436794%2fhow-to-capture-a-changing-one-line-program-output%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay