stdout

Redirect STDOUT and STDERR to python logger and also to jupyter notebook

吃可爱长大的小学妹 提交于 2020-03-25 16:06:45
问题 Important to know: I am working on jupyter notebook. I want to create a logger to which I will redirect the STDOUT and STDERR but I also want to see those outputs on the jupyter notebook output console. So far what I have implemented is: import logging import sys class StreamToLogger(object): """ Fake file-like stream object that redirects writes to a logger instance. """ def __init__(self, logger, log_level=logging.INFO): self.logger = logger self.log_level = log_level self.linebuf = '' def

Behavior of cout << hex with uint8 and uint16

浪子不回头ぞ 提交于 2020-03-17 11:00:26
问题 I'm noticing that cout << hex is giving me strange results, and I cannot find anywhere that answers why. What I am doing is simply assigning some values to both a uint8_t and uint16_t and then attempting to write them to stdout. When I run this: uint8_t a = 0xab; uint16_t b = 0x24de; cout << hex << a << endl; cout << hex << b << endl; That I get the result: $./a.out 24de $ with no value displayed for the uint8_t. What could be causing this? I didn't think there wouldn't be a cout

Python Popen().stdout.read() hang

牧云@^-^@ 提交于 2020-03-17 08:46:27
问题 I'm trying to get output of another script, using Python's subprocess.Popen like follows process = Popen(command, stdout=PIPE, shell=True) exitcode = process.wait() output = process.stdout.read() # hangs here It hangs at the third line, only when I run it as a python script and I cannot reproduce this in the python shell. The other script prints just a few words and I am assuming that it's not a buffer issue. Does anyone has idea about what I am doing wrong here? 回答1: You probably want to use

Python Popen().stdout.read() hang

自作多情 提交于 2020-03-17 08:44:25
问题 I'm trying to get output of another script, using Python's subprocess.Popen like follows process = Popen(command, stdout=PIPE, shell=True) exitcode = process.wait() output = process.stdout.read() # hangs here It hangs at the third line, only when I run it as a python script and I cannot reproduce this in the python shell. The other script prints just a few words and I am assuming that it's not a buffer issue. Does anyone has idea about what I am doing wrong here? 回答1: You probably want to use

Stderr and stdout for powershell with Invoke-Expression has no output or errors

回眸只為那壹抹淺笑 提交于 2020-02-27 09:19:28
问题 I am trying to get stdout and stderr from running a java process, and saw what seemed like an easy, cool way to do it, but it did not work: $command = "java -jar secretserver-jconsole.jar -s 123456 Password" Invoke-Expression $command -OutVariable output -ErrorVariable errors Write-Host "stdout: $output" Write-Host "stderr: $errors" Nothing displays with $output or $errors . I am using now: $output = cmd /c $command This does get me some stdout , but it is not ideal as I want $error message.

Can I capture STDOUT write events from a process in perl?

点点圈 提交于 2020-02-24 10:44:29
问题 I need (would like?) to spawn a slow process from a web app using a Minion queue. The process - a GLPK solver - can run for a long time but generates progress output. I'd like to capture that output as it happens and write it to somewhere (database? log file?) so that it can be played back to the user as a status update inside the web app. Is that possible? I have no idea (hence no code). I was exploring Capture::Tiny - the simplicity of it is nice but I can't tell if it can track write

Is setting a FILE* equal to stdout portable?

前提是你 提交于 2020-02-23 11:38:29
问题 I've got a function that needs to be able to write to either stdout, or to a file, depending on what the user wants. It defaults to standard out though. To accomplish this, I'm doing the following (minus error checking etc): FILE* out; if (writeToFile) { /*Code to open file*/; } else out = stdout; // ...rest of the function goes here if (out != stdout) fclose(out); This certainly does the trick, but I have no idea how portable it is. And if it's not, and/or there's another problem with it,

System.out.println() of Stream#reduce() unexpectedly prints “Optional[]” around result

蓝咒 提交于 2020-02-22 07:34:06
问题 I started to learn Lambda expressions of Java 8, and wrote below program to get sum of all numbers in the list: import java.util.Arrays; import java.util.List; public class MainClass { public static void main(String[] args) { List<Integer> number = Arrays.asList(1, 2, 3, 4, 5); System.out.println(number.stream().reduce((c,e) -> { return c + e; })); } } I was expecting the output to be: 15 but I got: Optional[15] Java version: 1.8.0_45 Please explain what does Optional[] means in the output?

wget hangs with -r and -O -

坚强是说给别人听的谎言 提交于 2020-02-22 06:03:11
问题 This is a VERY strange wget behavior. I'm on debian 7.2. wget -r -O - www.blankwebsite.com hangs forever. And I mean it hangs , it isn't searching through the internet, I can verify it with a strace . If I do this: while read R do wget -r -O - www.blankwebsite.com done < smallfile with smallfile containing a single line, the command exits in a few seconds. I tried also with wget -r -O - localhost/test.html with an empty test.html file, same results. To me, it sounds like a bug. Everything

Is there a way to flush stdout of a running process

让人想犯罪 __ 提交于 2020-02-21 11:10:34
问题 I have a long-running process with stdout redirected to a file. E.g.: ./my-script.sh > file.txt & Part of the stdout is still cached, but I would like to flush it to the file, to see the results earlier. Is there a way to do it? 回答1: The caching is handled by the libc. You can use the stdbuf command to change the buffer size: stdbuf -o0 ./my-script.sh > file.txt & -o0 sets the buffer size for stdout to 0 . Probably you also want -e0 for stderr. 回答2: You can inspect the /proc/ filesystem and