Hi all,
I was writing a bash script file to install an application which involves make file. I found that
echo "hello" | tee -a log.txt
can write the output to console as well as file.
How can I write the result of a make target command like this as the above method works only on console. This is the format of execution of make.
make target
With regards,
Athul R T
Hello Athul,
On Sat, Aug 29, 2020 at 12:29:37AM +0530, Athul R T wrote:
echo "hello" | tee -a log.txt
can write the output to console as well as file.
How can I write the result of a make target command like this as the above method works only on console. This is the format of execution of make.
It should work in shell script too. Scripts and commands communicate with us using 'streams'. There are 3 standard streams:
1. Standard input (stdin): The input to the command 2. Standard output (stdout): The output goes to this stream 3. Standard error (stderr): Error and diagnostic output of the command
The command output you normally see on a terminal is actually what the command writes to stdout and stderr.
The following syntax: cmd1 | cmd2
is called 'piping'. The stdout of cmd1 is sent (piped) to stdin of cmd2. Sometimes, you may want to pipe both stdout and stderr to another command. This is true for your case. You want both output and error message from shell script to be saved. The syntax is:
cmd1 2>&1 | cmd2
This means that the stderr (stream 2) is redirected to stdout (stream 1). After that, stdout is piped to cmd2.
tee command sends data stream from its stdin to a file as well as the stdout (terminal). So this should work inside the shell script:
make target 2>&1 | tee build.log
Regards, Gokul Das
Thank you. I already tried this and I saw that it didn't work. I have understood that the output for make is stderr. Anyway it is more clear now. So I run the script file and found that it wasn't writing the output. Then I learned that as I was navigating through folders and the make script was running in an inner folder, a log file is created there. That's why i thought it wasn't working.
This is what I did :
#created a log file
log=log_file.txt
#downloaded some file and extracted it. navigated into it and run the make file
make gfortran 2>&1 | tee -a $log
But the log is writing in the inner folder. How can I write all the log to a single file outside? One idea i got is to bring the file outside and merge it with original log file I defined. But is there an effective workaround?
Athul R T
On 29/08/20 1:22 am, Gokul Das B wrote:
Hello Athul,
On Sat, Aug 29, 2020 at 12:29:37AM +0530, Athul R T wrote:
echo "hello" | tee -a log.txt
can write the output to console as well as file.
How can I write the result of a make target command like this as the above method works only on console. This is the format of execution of make.
It should work in shell script too. Scripts and commands communicate with us using 'streams'. There are 3 standard streams:
- Standard input (stdin): The input to the command
- Standard output (stdout): The output goes to this stream
- Standard error (stderr): Error and diagnostic output of the command
The command output you normally see on a terminal is actually what the command writes to stdout and stderr.
The following syntax: cmd1 | cmd2
is called 'piping'. The stdout of cmd1 is sent (piped) to stdin of cmd2. Sometimes, you may want to pipe both stdout and stderr to another command. This is true for your case. You want both output and error message from shell script to be saved. The syntax is:
cmd1 2>&1 | cmd2
This means that the stderr (stream 2) is redirected to stdout (stream 1). After that, stdout is piped to cmd2.
tee command sends data stream from its stdin to a file as well as the stdout (terminal). So this should work inside the shell script:
make target 2>&1 | tee build.log
Regards, Gokul Das
fsug-tvm mailing list -- fsug-tvm@lists.fsci.org.in To unsubscribe send an email to fsug-tvm-leave@lists.fsci.org.in
Well I found a solution. Here is it
Run the make file from root directory by specifying the folder.
make target -C /path/to/make_directory
Thanks anyway.
Athul R T
On 29/08/20 1:56 am, Athul R T wrote:
Thank you. I already tried this and I saw that it didnt work. I have understood that the output for make is stderr. Anyway it is more clear now. So I run the script file and found that it wasn't writing the output. Then I learned that as I was navigating through folders and the make script was running in an inner folder, a log file is created there. That's why i thought it wasn't working.
This is what I did :
#created a log file
log=log_file.txt
#downloaded some file and extracted it. navigated into it and run the make file
make gfortran 2>&1 | tee -a $log
But the log is writing in the inner folder. How can I write all the log to a single file outside? One idea i got is to bring the file outside and merge it with original log file I defined. But is there an effective workaround?
Athul R T
On 29/08/20 1:22 am, Gokul Das B wrote:
Hello Athul,
On Sat, Aug 29, 2020 at 12:29:37AM +0530, Athul R T wrote:
echo "hello" | tee -a log.txt
can write the output to console as well as file.
How can I write the result of a make target command like this as the above method works only on console. This is the format of execution of make.
It should work in shell script too. Scripts and commands communicate with us using 'streams'. There are 3 standard streams:
- Standard input (stdin): The input to the command
- Standard output (stdout): The output goes to this stream
- Standard error (stderr): Error and diagnostic output of the command
The command output you normally see on a terminal is actually what the command writes to stdout and stderr.
The following syntax: cmd1 | cmd2
is called 'piping'. The stdout of cmd1 is sent (piped) to stdin of cmd2. Sometimes, you may want to pipe both stdout and stderr to another command. This is true for your case. You want both output and error message from shell script to be saved. The syntax is:
cmd1 2>&1 | cmd2
This means that the stderr (stream 2) is redirected to stdout (stream 1). After that, stdout is piped to cmd2.
tee command sends data stream from its stdin to a file as well as the stdout (terminal). So this should work inside the shell script:
make target 2>&1 | tee build.log
Regards, Gokul Das
fsug-tvm mailing list --fsug-tvm@lists.fsci.org.in To unsubscribe send an email tofsug-tvm-leave@lists.fsci.org.in
fsug-tvm mailing list -- fsug-tvm@lists.fsci.org.in To unsubscribe send an email to fsug-tvm-leave@lists.fsci.org.in