You are not logged in.

#1 2013-05-09 14:24:54

jgreen1tc
Member
From: St. Louis
Registered: 2011-05-16
Posts: 247

[SOLVED]How to handle output from commands?

I was wanting to view the output of commands as a text file, and was wondering if there was a way to achieve this. I know you can redirect the output to text, but I was wondering if there is any way to put it there after the command is run as opposed to redirecting it while it is run. So far my searches aren't looking good and I'm leaning towards thinking that it isn't possible and I should just redirect the output before hand, but I wanted to see if there was a way I missed. Does anyone know of any?

Last edited by jgreen1tc (2013-05-10 12:50:39)

Offline

#2 2013-05-09 14:31:10

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,493
Website

Re: [SOLVED]How to handle output from commands?

I'm not sure I really understand.  You want to run a command, then *after the fact* put its output into a text file?  Unless you have a spare flux capacitor laying around, I don't see how this would make any sense: how would your computer know which output to put into a text file?  Again, I think I must be misunderstanding, perhaps you could give an example of how this could be used to clarify.

Also, if you can compare/contrast to `tee` that would help.  Or perhaps tee is just what you need - it "duplicates" output and sends one copy to stdout as usual and one copy to a file.

EDIT: I suppose you could also get really creative (depending on your terminal and environment) with things like xdotool, xsel, and others to "copy and paste" everything between the last prompt and the previous prompt.

EDIT2: this has a really cool result "bash | tee mylogfile".  This gives you a normal bash session, but "logs" all the output in logfile.  You could then do some wizardry with grep, or awk to get only the ouput from the last command from that logfile.  And this does seem to work in "real time".  I can see the output of the last command in the log file from within the bash session that is being logged.  This does not log your PS1 which would be useful for extracting the last output only, but it does log anything that is echoed from PROMPT_COMMAND.  So you could put some sort of delineating marking in PROMPT_COMMAND, then run a logged session, and show the contents of the log only between the last two markers.

Last edited by Trilby (2013-05-09 14:40:52)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2013-05-09 14:34:37

Scimmia
Bug Wrangler
Registered: 2012-09-01
Posts: 4,784

Re: [SOLVED]How to handle output from commands?

Copy/Paste is the only way I know of.

Offline

#4 2013-05-09 16:02:06

wierob
Member
Registered: 2013-05-09
Posts: 6

Re: [SOLVED]How to handle output from commands?

You could use the 'script' command which makes a typescript of a terminal session. The resulting  file would contain your commands as well as the output. See 'man script' for more details.

Offline

#5 2013-05-09 16:14:02

x33a
Forum Moderator
Registered: 2009-08-15
Posts: 3,246
Website

Re: [SOLVED]How to handle output from commands?

There is a hardcopy command for GNU Screen, and it can do what you want, but not automatically.

Offline

#6 2013-05-10 04:39:33

jgreen1tc
Member
From: St. Louis
Registered: 2011-05-16
Posts: 247

Re: [SOLVED]How to handle output from commands?

wierob wrote:

You could use the 'script' command which makes a typescript of a terminal session. The resulting  file would contain your commands as well as the output. See 'man script' for more details.

This command is pretty much exactly what I was looking for. Thanks.

Offline

#7 2013-05-10 09:44:32

rix
Member
Registered: 2012-07-25
Posts: 221

Re: [SOLVED]How to handle output from commands?

Don't forget [SOLVED].

Offline

Board footer

Powered by FluxBB