stdout

python - how can I redirect the output of unittest? Obvious solution doesn't work

懵懂的女人 提交于 2019-12-05 04:17:32
Here is my code: import unittest import sys import os class DemoTest(unittest.TestCase): def test_one(self): print "test one" self.assertTrue(True) def test_two(self): print "test two" self.assertTrue(False) if __name__ == '__main__': dirpath = os.path.dirname(os.path.abspath(__file__)) sys.stdout = open(dirpath+'/test_logs/demo_test.stdout.log', 'w') sys.stderr = open(dirpath+'/test_logs/demo_test.stderr.log', 'w') test_program = unittest.main(verbosity=0, exit=False) When I run this, the contents of demo_test.stdout.log is only: test one test two on the screen I still see the output from

Is there a way to configure PuTTY or other terminal to flash the taskbar on next output to stdout?

南楼画角 提交于 2019-12-05 04:11:43
I'm specifically looking for a solution for PuTTY but also interested for other terminal emulators, like Gnome Terminal. My thought is it would be useful if I start a tar zxvf to be able to set a trigger on the terminal emulator, minimize it, and on next output to stdout/stderr I get a notification in the task bar that the command has finished. Adam Lehenbauer This works for me: echo -e "\a" Then update your PuTTY session to use the Visual Bell, and set "Taskbar/caption indication on bell" to Flashing or Steady. Then run this command after your tar completes: tar xvzf file ; echo -e "\a" Here

Java: What's the reason behind System.out.println() being that slow?

笑着哭i 提交于 2019-12-05 03:51:37
For small logical programs that can be done in a text editor, for tracing I use the classic System.out.println() . I guess you all know how frustrating it is to use that in a block of high number of iterations. Why is it so slow? What's the reason behind it? This has nothing whatsoever to do with the JVM. Printing text to screen simply involves a lot of work for the OS in drawing the letters and especially scrolling. If you redirect System.out to a file, it will be much faster. This is very OS-dependent. For example, in Windows, writing to the console is a blocking operation, and it's also

Golang: Child Processes become Zombies

你。 提交于 2019-12-05 03:50:59
I have an application in Go that reroutes the STDIN and STDOUT of binaries and then runs them. In a nutshell I'm doing: - create command object with the binary path (lets call the object command A) - create command object with the binary path (calling it command B) - set the stdout of command B to the stdin of Command A - start command A - start command B I noticed whenever the process for command B exits while command A is running, it becomes a zombie process in the process table. Here's an example: commandA := exec.Command("samplebin") commandB := exec.Command("sample2bin") cmdAStdin :=

Redirecting native dll stdout/stderr from within C#

旧城冷巷雨未停 提交于 2019-12-05 02:20:34
问题 I'm trying to redirect the output of a third-party native dll which outputs to stdout/stderr from within C#. The output of both stdout and stderr should go to a log file. Here's my idea (x2 for two streams): Create an AnonymousPipeServerStream Get the pipe's handle via _outServer.SafePipeHandle.DangerousGetHandle() Use P/Invoke to call SetStdHandle with said handle Create an AnonymousPipeClientStream connected to the server stream Create a thread to sit in a loop reading from the

Passing data between Python and C# without writing a file

笑着哭i 提交于 2019-12-05 01:58:49
问题 I would like to pass binary information between Python and C#. I would assume that you can open a standard in/out channel and read and write to that like a file, but there are a lot of moving parts, and I don't know C# too well. I want to do this sort of thing, but without writing a file. # python code with open(DATA_PIPE_FILE_PATH, 'wb') as fid: fid.write(blob) subprocess.Popen(C_SHARP_EXECUTABLE_FILE_PATH) with open(DATA_PIPE_FILE_PATH, 'rb') as fid: 'Do stuff with the data' // C# code

Python multiple subprocess with a pool/queue recover output as soon as one finishes and launch next job in queue

99封情书 提交于 2019-12-05 01:25:50
I'm currently launching a subprocess and parsing stdout on the go without waiting for it to finish to parse stdout. for sample in all_samples: my_tool_subprocess = subprocess.Popen('mytool {}'.format(sample),shell=True, stdout=subprocess.PIPE) line = True while line: myline = my_tool_subprocess.stdout.readline() #here I parse stdout.. In my script I perform this action multiple times, indeed depending on the number of input samples. Main problem here is that every subprocess is a program/tool that uses 1 CPU for 100% while it's running. And it takes sometime.. maybe 20-40 min per input. What I

How can I read process output that has not been flushed?

别等时光非礼了梦想. 提交于 2019-12-05 00:32:40
Consider this little programm be compiled as application.exe #include <stdio.h> int main() { char str[100]; printf ("Hello, please type something\n"); scanf("%[^\n]s", &str); printf("you typed: %s\n", str); return 0; } Now I use this code to start application.exe and fetch its output. #include <stdio.h> #include <iostream> #include <stdexcept> int main() { char buffer[128]; FILE* pipe = popen("application.exe", "r"); while (!feof(pipe)) { if (fgets(buffer, 128, pipe) != NULL) printf(buffer); } pclose(pipe); return 0; } My problem is that there is no output until I did my input. Then both

How to print stdout immediately?

一个人想着一个人 提交于 2019-12-05 00:02:24
How can I immediately output stdout ? stdout is going to print after all input is complete. require 'open3' def run(cmd) Open3.popen3(cmd) do |stdin, stdout, stderr, thread| Thread.new do stdout.each {|l| puts l} end Thread.new do while thread.alive? stdin.puts $stdin.gets end end thread.join end end run ("ruby file_to_test.rb") file_to_test.rb: puts "please, enter s" puts "please, enter q" s = gets.chomp! q = gets.chomp! puts s puts q The result after running main.rb is: somestring somestring2 please, enter s please, enter q somestring somestring2 How can I immediately output stdout ? Ruby is

Capture standard output and still display it in the console window

限于喜欢 提交于 2019-12-04 23:49:24
问题 I'm spawning a child process that runs in a visible console window (it's a batch file that runs MSBuild), and I'd like to have the output generated by the process displayed in the visible console window, as well as capture that output so I can process it in code. I've read several other questions and the MSDN documentation dealing with ProcessStartInfo.RedirectStandardOutput and the like, and I can capture the output from the redirected stream and process it in code just fine: Process msBuild