stdout

Suppress STDOUT from a Ruby C extension

本秂侑毒 提交于 2019-12-23 04:38:28
问题 I'm using the gem dep_selector in a project and can't figure out how to suppress the stdout from the library's C extensions. The code in question I want to suppress is here: https://github.com/RiotGames/knife_cookbook_dependencies/blob/master/lib/kcd/shelf.rb#L26 I tried this: real_stdout = $stdout $stdout = StringIO.new real_stderr = $stderr $stderr = StringIO.new puts "This gets suppressed correctly" selector.find_solution( ... ) # still prints to the terminal but I still get dep_selector

Get both STDOUT and STDERR of a program or script to a variable in perl [duplicate]

这一生的挚爱 提交于 2019-12-23 04:28:17
问题 This question already has answers here : How can I get the CPU time for a perl system call? (3 answers) Closed 2 years ago . I did lot of google to redirect the both STDOUT and STDERR of a program to a variable in perl, Initially i tried using both open and backticks , but failed to capture Error signal to the variable. I am posting this question because Now I got the solution and hope it may helps others.. 回答1: To get both STDOUT and STDERR into a variable use following code snippet using

Redirect stdout in another thread

我怕爱的太早我们不能终老 提交于 2019-12-23 03:29:14
问题 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(

What to do with unneeded streams from an external process?

家住魔仙堡 提交于 2019-12-23 03:12:31
问题 When I execute a command in a separate process, for example by using the Runtime.getRuntime().exec(...) method, whose JavaDoc states: Executes the specified command and arguments in a separate process. What do I need to do with the streams from this process, knowing that the process shall live until the Java program exists? (this is a detail but the Java program takes care of killing this process and the process itself has a safety built-in where it kills itself should it notice that the Java

Strange behaviour when redirecting stdout in C

做~自己de王妃 提交于 2019-12-22 18:39:51
问题 I'm trying to redirect stdout to a file and then restore it back to original in C, but I'm facing the following strange issue - the following piece of code succesfully writes in stdout in stdout in stdout and in file in the respective file which is all OK. #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #define STDOUT 1 int main(int argc, char* argv[]){ printf("in stdout \n"); int old_out = dup(STDOUT); close(STDOUT); int fd = open("./redirected",O_CREAT|O_RDWR|O_TRUNC,0777); printf

redirect stdout to a variable in C

廉价感情. 提交于 2019-12-22 18:02:20
问题 I've done a lot of research on how to redirect stdout to a variable in C but no success. All I see is redirection of stdout to a file using dup2 and freopen which is not what I need. I want to know if is it even possible to redirect it to a variable without redirecting it first to a file? Im using ubuntu and C to create the code. Im uaing GCC 4.7.3 as the compiler. I did use dup2 and freopen and tried to do some work around but after some time. I realized that redirecting it to a file first

Getting the entire output from subprocess.Popen

独自空忆成欢 提交于 2019-12-22 12:36:22
问题 I'm getting a slightly weird result from calling subprocess.Popen that I suspect has a lot to do with me being brand-new to Python. args = [ 'cscript', '%USERPROFILE%\\tools\\jslint.js','%USERPROFILE%\\tools\\jslint.js' ] p = Popen(args, stdout=PIPE, shell=True).communicate()[0] Results in output like the following (the trailing double \r\n is there in case it's important) Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.\r\n\r\n If I run

Redirect stdout of two processes to another process's stdin in Linux C

倖福魔咒の 提交于 2019-12-22 08:41:11
问题 I'm running into problem about redirect stdout of multi process. Assuming I have process A, I use fork() in A and then I get process A and B. And I use fork() in B, finally I get process A, B and C. Both B and C are implementing other program by exec(). Now, I try to redirect the stdout of A and B to stdin of C with two pipes. #include<unistd.h> #include<stdio.h> #include<sty/types.h> int main() { int AtoC [2]; pipe(AtoC); int fd1,fd2; fd1=fork(); if(fd1>0) { /***In process A, I do the

Create a cmd window and write to it from C# application

丶灬走出姿态 提交于 2019-12-22 07:59:43
问题 I am developing a C# component for Grasshopper for Rhino. As I am running some pretty heavy iterative analysis I would like to output results continuously to a cmd window just to make sure that the analysis is actually running. Here's what I tried: using System.Diagnostics; Result results = new Result(); Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.CreateNoWindow = false;

Python subprocess with stdout redirect returning an int

不问归期 提交于 2019-12-22 06:35:36
问题 I am trying to read out data from a set of print statements in a C++ program that is being run using a subprocess. C++ code: printf "height= %.15f \\ntilt = %.15f \(%.15f\)\\ncen_volume= %.15f\\nr_volume= %.15f\\n", height, abs(sin(tilt*pi/180)*ring_OR), abs(tilt), c_vol, r_vol; e; //e acts like a print Python code: run = subprocess.call('Name', stdout = subprocess.PIPE, env={'LANG':'C++'}) data, error = run.communicate() However instead of getting the data, all I am getting is a single int,