tee

Get exit code from subshell through the pipes

两盒软妹~` 提交于 2019-11-26 20:56:37
问题 How can I get exit code of wget from the subshell process? So, main problem is that $? is equal 0. Where can $?=8 be founded? $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); echo "$?" 0 It works without tee , actually. $> OUT=$( wget -q "http://budueba.com/net" ); echo "$?" 8 But ${PIPESTATUS} array (I'm not sure it's related to that case) also does not contain that value. $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); echo "${PIPESTATUS[1]}" $> OUT=$(

How can I implement 'tee' programmatically in C?

半腔热情 提交于 2019-11-26 17:23:25
问题 I'm looking for a way in C to programmatically (ie, not using redirection from the command line) implement 'tee' functionality such that my stdout goes to both stdout and a log file. This needs to work for both my code and all linked libraries that output to stdout. Any way to do this? 回答1: You could popen() the tee program. Or you can fork() and pipe stdout through a child process such as this (adapted from a real live program I wrote, so it works!): void tee(const char* fname) { int pipe_fd

Capture stdout to a variable but still display it in the console

廉价感情. 提交于 2019-11-26 15:17:58
I have a bash script which calls several long-running processes. I want to capture the output of those calls into variables for processing reasons. However, because these are long running processes, I would like the output of the rsync calls to be displayed in the console in real-time and not after the fact. To this end, I have found a way of doing it but it relies on outputting the text to /dev/stderr. I feel that outputting to /dev/stderr is not a good way of doing things. VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee /dev/stderr) VAR2=$(rsync -r -t --out-format='%n%L' --delete -s

Force line-buffering of stdout when piping to tee

蹲街弑〆低调 提交于 2019-11-26 06:48:57
Usually, stdout is line-buffered. In other words, as long as your printf argument ends with a newline, you can expect the line to be printed instantly. This does not appear to hold when using a pipe to redirect to tee . I have a C++ program, a , that outputs strings, always \n -terminated, to stdout . When it is run by itself ( ./a ), everything prints correctly and at the right time, as expected. However, if I pipe it to tee ( ./a | tee output.txt ), it doesn't print anything until it quits, which defeats the purpose of using tee . I know that I could fix it by adding a fflush(stdout) after

Force line-buffering of stdout when piping to tee

自作多情 提交于 2019-11-26 01:57:35
问题 Usually, stdout is line-buffered. In other words, as long as your printf argument ends with a newline, you can expect the line to be printed instantly. This does not appear to hold when using a pipe to redirect to tee . I have a C++ program, a , that outputs strings, always \\n -terminated, to stdout . When it is run by itself ( ./a ), everything prints correctly and at the right time, as expected. However, if I pipe it to tee ( ./a | tee output.txt ), it doesn\'t print anything until it

Displaying Windows command prompt output and redirecting it to a file

那年仲夏 提交于 2019-11-26 00:20:04
问题 How can I run a command-line application in the Windows command prompt and have the output both displayed and redirected to a file at the same time? If, for example, I were to run the command dir > test.txt , this would redirect output to a file called test.txt without displaying the results. How could I write a command to display the output and redirect output to a file in the Windows command prompt, similar to the tee command on Unix? 回答1: To expand on davor's answer, you can use PowerShell

How to duplicate sys.stdout to a log file?

家住魔仙堡 提交于 2019-11-25 23:17:59
问题 Edit: Since it appears that there\'s either no solution, or I\'m doing something so non-standard that nobody knows - I\'ll revise my question to also ask: What is the best way to accomplish logging when a python app is making a lot of system calls? My app has two modes. In interactive mode, I want all output to go to the screen as well as to a log file, including output from any system calls. In daemon mode, all output goes to the log. Daemon mode works great using os.dup2() . I can\'t find a