stdout

Print the stdout from exec command in real time in Go [duplicate]

江枫思渺然 提交于 2019-12-10 19:12:36
问题 This question already has an answer here : How can I redirect the stdout and stderr of a command to both the console and a log file while outputting in real time? (1 answer) Closed last year . I have a small Go tool which basically allows the user to define an command that than will be run using os/exec . My problem is that I want to show the user the output (stdout/stderr) of the command. An example could look like this: The user defines a command that in the end is sh test.sh . Content of

Redirecting stdout to file after a fork()

余生颓废 提交于 2019-12-10 18:49:05
问题 I'm working on a simple shell, but right now I am just trying to understand redirection. I'm just hard coding an ls command and trying to write it to a file for now. Currently, the ls runs, and the output file is created, but the output still goes to stdout and the file is blank. I'm confused as to why. Thanks in advance. Here is my code: int main() { int ls_pid; /* The new process id for ls*/ char *const ls_params[] = {"/bin/ls", NULL}; /* for ls */ int file; /* file for writing */ /* Open

How do I redirect terminal output from a C program to System.out with JNI?

血红的双手。 提交于 2019-12-10 17:57:20
问题 I am invoking a C library via JNI that prints to stdout. How can I redirect this output to System.out? 回答1: System.out is stdout . Is there some more fundamental problem you're having (mixed up output, perhaps?). Since another member has also mentioned that last point - I should explain further: System.out and stdout both correspond to file descriptor #1. However both Java's OutputStream (and derived classes) and C's stdio library have their own (independent) buffering mechanisms so as to

Perl Cannot Binmode STDOUT After Untie Filehandle

点点圈 提交于 2019-12-10 15:53:51
问题 I need to disable progressive buffering of an HTTP response. I've got this working in Perl using a file handle class: $|=1; $TIE = tie(*STDOUT,__PACKAGE__); Print statements are stored in an array and are retrieved via the following: $buffer = tied *STDOUT; $buffer = join('', @$buffer); undef $TIE; untie(*STDOUT); If the HTTP response is text/html , it correctly displays in the browser. However, for binary streams, I can't set binmode on STDOUT after it is untied, and the contents are

Why to turn off the standard output buffer when multithreading?

為{幸葍}努か 提交于 2019-12-10 15:46:35
问题 I'm trying to learn on multithreading, and I have a simple question. On most of the examples I find, the standard output buffer is turned off before letting multiple threads to use it with: setbuf(stdout,NULL); Why? Codes print the same if I remove that line on them! 回答1: It is possible that they would not print out the same - when the output is buffered it may not be displayed right away which can change the order in which the lines are output between threads. Turning off buffering makes

how to get output from a pipe connection before closing it in R?

空扰寡人 提交于 2019-12-10 14:18:57
问题 In R, we can open a pipe connection using pipe() and write to it. I observed the following situation that I do not quite understand. Let's use a python pipe for example: z = pipe('python', open='w+') cat('x=1\n', file=z) cat('print(x)\n', file=z) cat('print(x+2)\n', file=z) cat('print(x+2\n', file=z) cat(')\n', file=z) close(z) What I was expecting was the output from print() would be immediately shown in the R console, but the fact is the output comes only after I close the pipe connection:

Python `print` passing extra text to sys.stdout?

浪子不回头ぞ 提交于 2019-12-10 14:09:06
问题 This is probably something stupid I am missing but it has really got me hung up on a larger project ( c extension) that I am writing. Why is print "Hello, World!" passing None and an extra \n to sys.stdout here? >>> import sys >>> class StdOutHook: ... def write(self, text): ... sys.__stdout__.write("stdout hook received text: %s\n" % repr(text)) ... >>> class StdErrHook: ... def write(self, text): ... sys.__stderr__.write("stderr hook received text: %s\n" % repr(text)) ... >>> sys.stdout =

How can close and reopen STDOUT in Perl?

老子叫甜甜 提交于 2019-12-10 12:53:08
问题 I'd like to close STDOUT to prevent my code from outputing a particular image that I need for further computation but do not want on my web page. So i want to close STDOUT, do what I have to do with my code, then reopen STDOUT to output stuff to a web page. (Not to a file) What I tried is: close STDOUT; # my code here open STDOUT; This doesn't work... Thanks 回答1: There are several ways to approach your problem, and many of them do not require you to close STDOUT and risk fubaring your program

Data corruption Piping between C++ and Python

故事扮演 提交于 2019-12-10 12:44:12
问题 I am writing some code that takes binary data from Python, Pipes it to C++, does some processing on the data, (in this case calculating a mutual information metric) and then pipes the results back to python. While testing I have found that everything works fine if the data I send is a set of 2 arrays with dimensions less than 1500 X 1500, but if I send 2 arrays that are 2K X 2K I get back a lot of corrupted nonsense. I currently believe the algorithmic portion of the code is fine because it

Spurious newlines added in Django management commands

痞子三分冷 提交于 2019-12-10 12:41:36
问题 Running Django v1.10 on Python 3.5.0: from django.core.management.base import BaseCommand class Command(BaseCommand): def handle(self, *args, **options): print('hello ', end='', file=self.stdout) print('world', file=self.stdout) Expected output: hello world Actual output: hello world How do I correctly pass the ending character? I currently use a workaround of setting explicitly: self.stdout.ending = '' But this hack means you don't get all the features of the print function, you must use