stdout

Node.js spawning a child process interactively with separate stdout and stderr streams

余生长醉 提交于 2019-12-17 23:35:48
问题 Consider the following C program (test.c): #include <stdio.h> int main() { printf("string out 1\n"); fprintf(stderr, "string err 1\n"); getchar(); printf("string out 2\n"); fprintf(stderr, "string err 2\n"); fclose(stdout); } Which should print a line to stdout, a line to stderr, then wait for user input, then another line to stdout and another line to stderr. Very basic! When compiled and run on the command line the output of the program when complete (user input is received for getchar()):

Getting output of a system command from stdout in C

◇◆丶佛笑我妖孽 提交于 2019-12-17 20:03:46
问题 I'm writing a C program under Android/Linux that runs a system command. The command outputs some text to stdout, and I'm trying to capture the output into a string or character array. For example: system("ls"); would list the contents of the current directory to stdout, and I would like to be able to capture that data into a variable programmatically in C. How do I do this? Thanks. 回答1: You want to use popen . It returns a stream, like fopen . However, you need to close the stream with pclose

How to write buffer content to stdout?

故事扮演 提交于 2019-12-17 18:39:20
问题 Is there any chance to write the content of the current vim buffer to stdout? I'd like to use vim to edit content that was passed via stdin - without the need of a temporary file to retrieve the modified content (on Linux/Unix). Is it possible that a plugin/script - that act on quit or save put the buffer content to stdout? 回答1: I think :w !tee would work perfectly, 回答2: Since you use Linux/Unix, you might also be interested in trying out moreutils. It provides a command called vipe , which

Output raw image from Imagick image in PHP

巧了我就是萌 提交于 2019-12-17 18:28:20
问题 I'm using Imagick lib to do some modifications to original image. Then I'd like to output it directly to browser without saving. Is there a way to do that? I tried to use Imagick::writeImage('STDOUT') (empty output) and 'php://stdout' with error "Unable to write to file". Any ideas? :) 回答1: You just need to echo your imagick object: $img = new Imagick($file); header('Content-Type: image/'.$img->getImageFormat()); echo $img; 回答2: I believe what Schneck meant is: header('Content-Type: '.$mime

How do I see stdout when running Django tests?

孤街浪徒 提交于 2019-12-17 18:13:36
问题 When I run tests with ./manage.py test , whatever I send to the standard output through print doesn't show. When tests fail, I see an "stdout" block per failed test, so I guess Django traps it (but doesn't show it when tests pass). 回答1: Checked TEST_RUNNER in settings.py , it's using a project-specific runner that calls out to Nose. Nose has the -s option to stop it from capturing stdout , but if I run: ./manage.py test -s manage.py captures it first and throws a "no such option" error. The

Command to get nth line of STDOUT

六月ゝ 毕业季﹏ 提交于 2019-12-17 17:21:45
问题 Is there any bash command that will let you get the nth line of STDOUT? That is to say, something that would take this $ ls -l -rw-r--r--@ 1 root wheel my.txt -rw-r--r--@ 1 root wheel files.txt -rw-r--r--@ 1 root wheel here.txt and do something like $ ls -l | magic-command 2 -rw-r--r--@ 1 root wheel files.txt I realize this would be bad practice when writing scripts meant to be reused, BUT when working with the shell day to day it'd be useful to me to be able to filter my STDOUT in such a way

Can I use RSpec to mock stdin/stdout to test console reads & writes?

怎甘沉沦 提交于 2019-12-17 16:26:17
问题 My Ruby program reads lines from stdin and uses puts to print to stdout (the terminal). Can I use RSpec to test the reads and writes? Can I inject a string to my program like it was written in stdin and at the same time check the output? line = STDIN.read.chomp.split Also, I have the reads and writes in a loop, until line[0] is "quit". Can I test while the loop is running or should I call subject.read_in and subject.write_out ? 回答1: You can use mocks and have the method called more than once

Where do writes to stdout go when launched from a cygwin shell, no redirection

僤鯓⒐⒋嵵緔 提交于 2019-12-17 15:57:16
问题 I have an application, let's call it myapp.exe, which is dual-mode console/GUI, built as /SUBSYSTEM:WINDOWS (There's a tiny 3KB shim myapp.com to cause cmd.exe to wait to display the new prompt.) If I launch from a command prompt: myapp -> cmd.exe runs myapp.com which runs myapp.exe. stdout is initially a detached console, by using AttachConsole and freopen("CONOUT$", "w", stdout) my output appears in the command box. OK myapp.exe -> cmd.exe displays the prompt too early (known problem),

In Java, how can I redirect System.out to null then back to stdout again?

北战南征 提交于 2019-12-17 15:46:47
问题 I've tried to temporarily redirect System.out to /dev/null using the following code but it doesn't work. System.out.println("this should go to stdout"); PrintStream original = System.out; System.setOut(new PrintStream(new FileOutputStream("/dev/null"))); System.out.println("this should go to /dev/null"); System.setOut(original); System.out.println("this should go to stdout"); // This is not getting printed!!! Anyone have any ideas? 回答1: Man, this is not so good, because Java is cross-platform

Difference between $stdout and STDOUT in Ruby

不问归期 提交于 2019-12-17 15:24:22
问题 In Ruby, what is the difference between $stdout (preceded by a dollar sign) and STDOUT (in all caps)? When doing output redirection, which should be used and why? The same goes for $stderr and STDERR . Edit: Just found a related question. 回答1: $stdout is a global variable that represents the current standard output. STDOUT is a constant representing standard output and is typically the default value of $stdout . With STDOUT being a constant, you shouldn't re-define it, however, you can re