How do I run a command while logging the output to a file?


Ben Morel

I have a console application that needs to run as part of the deployment of a new application version on the server.

This console application is designed to output to the console and cannot be changed.

I want to run it normally, but log stdout and stderr to a file and then output them to the console.

How can I do this on Linux?

Goldilocks

You can use tee. E.g:

ls -l / | tee tmp.txt

will print to standard output and tmp.txtwill contain a copy of the output. If you want to include stderr in tmp.txt, do:

ls -l / 2>&1 | tee tmp.txt

Related


How do I run a command while logging the output to a file?

Ben Morel I have a console application that needs to be run as part of the deployment of a new application version on the server. This console application is designed to output to the console and cannot be changed. I want to run it normally, but log stdout and

How do I get the command to run after logging in and starting x?

user xset led 3What if I need to run after every login ? I am using Manjaro from gnome. hammock If you're using a display manager (eg Gnome-native GDM) , look at ~/.xprofile , where you put the command to invoke the x server after it has started but before any

How do I get the command to run after logging in and starting x?

user xset led 3What if I need to run after every login ? I am using Manjaro from gnome. hammock If you're using a display manager (eg Gnome-native GDM) , look at ~/.xprofile , where you put the command to invoke the x server after it has started but before any

How can I pipe the output of a file to a command?

cjm2671 I am trying to do something like: cat my_key.pub | send_key_to_server It let me try an experiment like this: cat my_key.pub | echo No output was produced. Finally I tried: echo "hello" | echo This also produces no output. I thought it would say "hel

How can I pipe the output of a file to a command?

cjm2671 I am trying to do something like: cat my_key.pub | send_key_to_server It let me try an experiment like this: cat my_key.pub | echo No output was produced. Finally I tried: echo "hello" | echo This also produces no output. I thought it would say "hel

How can I copy the output of a command to a file?

Nikhil Saini This is part of the long code. ExecutableName = 'op.test' InterfaceName = 'TN3270' command = ('./'+ExecutableName+' '+InterfaceName+' 2>&1 | tee -a filename.txt') os.system(command) print command In the end, the command executes correctly, but t

How to run sed command to get sed file and output sql file

Alex Weber Updated question : http://pastebin.com/SrVC8PvW : sed file - csv2sql.sed: s|\([A-Z]*\),\([A-Z]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([0-9]*\)|INSERT INTO `Schedule` (`ID`,`YEAR`,`NUMBER`,`TeamR1`,`TeamR2`, `TeamR3`, `TeamB1`, `Tea

How to run sed command to get sed file and output sql file

Alex Weber Updated question : http://pastebin.com/SrVC8PvW : sed file - csv2sql.sed: s|\([A-Z]*\),\([A-Z]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([0-9]*\)|INSERT INTO `Schedule` (`ID`,`YEAR`,`NUMBER`,`TeamR1`,`TeamR2`, `TeamR3`, `TeamB1`, `Tea

How do I execute a command while typing?

immortal fire How to execute some command while waiting for input? like this: while(/*taking input*/) { sleep(15); cout<<"You still there?"; //... } So it asks for input, but executes the command while waiting for ENTER to be pressed. Is it