stdout

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

一个人想着一个人 提交于 2019-12-06 18:41:54
问题 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

stdout vs console.write in c#

折月煮酒 提交于 2019-12-06 17:13:57
问题 I am VERY new to C#/programming and as a learning exercise completed an online challenge to change text to lowercase. The challenge specified it must 'print to stdout' yet I completed the challenge by using Console.Writeline using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lowercase { class Program { static void Main(string[] args) { using ( StreamReader reader = new StreamReader("TextFile1.txt")) {

Redirect stdout in another thread

☆樱花仙子☆ 提交于 2019-12-06 16:07:51
I am trying to write a test that will redirect the stdout of a main method, but it seems that once I call the main, it seems to start on another thread and I cannot capture the output. Here is the code: This works: val baos = new ByteArrayOutputStream val ps = new PrintStream(baos) System.setOut(ps) print("123") Assert.assertEquals("123", baos.toString) This does not: val baos = new ByteArrayOutputStream val ps = new PrintStream(baos) System.setOut(ps) GameRunner.main(_) Assert.assertEquals("123", baos.toString) .... object GameRunner { def main(args: Array[String]) { print("123") How can I

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

不羁的心 提交于 2019-12-06 11:56:00
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? Does it has any significance in Java 8? From the Java Docs for Stream#reduce() , we see that the reduce

How to redirect stderr in Python? Via Python C API?

…衆ロ難τιáo~ 提交于 2019-12-06 11:39:57
问题 This is a combination of my two recent questions: [1] Python instance method in C [2] How to redirect stderr in Python? I would like to log the output of both stdout and stderr from a python script. The thing I want to ask is, to create a new type according to [1] seems fairly complicated. Does it simplifies the things if there was no need to expose the new type to Python, i.e. it would only exist in C? I mean, when Python prints something it goes to "Objects/fileobject.c" and there in

Print a string to stdout using Logstash 1.4?

六眼飞鱼酱① 提交于 2019-12-06 11:26:26
问题 So I was testing this config for using metrics from the Logstash website here. input { generator { type => "generated" } } filter { if [type] == "generated" { metrics { meter => "events" add_tag => "metric" } } } output { # only emit events with the 'metric' tag if "metric" in [tags] { stdout { message => "rate: %{events.rate_1m}" } } } But it looks like the "message" field for stdout was deprecated. What is the correct way to do this in Logstash 1.4? 回答1: So figured it out after looking at

Show output from child scripts in the parent console window

会有一股神秘感。 提交于 2019-12-06 09:55:00
问题 I'm calling VBScripts from inside of a VBScript and I want their console output to appear in the window from which I'm calling them. So when I have this code WScript.Stdout.WriteLine( "Checking out unit tests" ) ObjWshShell.Run "%comspec% \c checkoutUnitTests.vbs", 0, True the the only output I see is Checking out unit tests when I want to see all the output from checkoutUnitTests.vbs concatenated onto that output in the same window. How do I do this? 回答1: You should try to use .Exec and

Capture stdout to a string and output it back to stdout in C

瘦欲@ 提交于 2019-12-06 09:40:22
C language is used. I have a function that writes to stdout. I would like to capture that output, modify it a bit (replacing some strings). And than output it again to the stdout. So I want to start with: char huge_string_buf[MASSIVE_SIZE]; freopen("NUL", "a", stdout); -OR- freopen("/dev/null", "a", stdout); setbuf(stdout, huge_string_buffer); /* modify huge_string_buffer */ The question is now, how do I output the huge_string_buffer back to the original stdout? One idea is to mimic the functionality of the standard Unix utility tee , but to do so entirely within your program, without relying

Printing output in realtime from subprocess

喜你入骨 提交于 2019-12-06 09:20:24
I'm trying to print stdout in realtime for a subprocess but it looks like stdout is buffered even with bufsize=0 and I can't figure out how to make it work, I always have a delay. The code I tried : p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0) line = p.stdout.readline() while line: sys.stdout.write(line) sys.stdout.flush() # DO OTHER STUFF line = p.stdout.readline() Also tried with for line in iter(p.stdout.readline, b'') instead of the while loop and with read(1) instead of readline() . Always the same result, the output gets delayed by a lot of

Truncate #inspect output in irb (ruby)

久未见 提交于 2019-12-06 08:56:59
问题 I want to truncate #inspect output in irb (a large output must be cropped to MAX_LEN). Currently, I override :inspect, :to_s methods for all specific objects. Is there are other solution? change $stdout ? other? 回答1: For a clean solution, gem install hirb . hirb pages irb's returned values if they get too long. If you want to monkeypatch irb: module IRB class Irb def output_value @context.last_value.to_s.slice(0, MAX_LEN) end end end I don't recommend this because it's a hack and breaks any