stdout

Unix/C++: Open new terminal and redirect output to it

99封情书 提交于 2020-01-03 17:35:10
问题 My program (C++ on Solaris 10) writes output via wcout to its terminal when it is started from a shell. But when I execute it from within Sun Studio or the file manager is does not have a terminal and the ouput appears in the Sun Studio output window or nowhere at all. I would like it to open its own terminal window in any of the three cases and attach wcout to this terminal window. I want this to be done be the program itself with C++ system calls not by the way how the program is executed

perl6/rakudo: Does perl6 enable “autoflush” by default?

放肆的年华 提交于 2020-01-03 15:59:39
问题 #!perl6 use v6; my $message = "\nHello!\n\nSleep\nTest\n\n"; my @a = $message.split( '' ); for @a { sleep 0.3; .print; } Does perl6 enable "autoflush" by default. With perl5 without enabling "outflush" I don't get this behavior. 回答1: Rakudo enables autoflush by default; the specification is silent about the default. 回答2: Quoting from the docs regarding auto flush: ‘No global alternative available. TTY handles are unbuffered by default, for others, set out-buffer to zero or use :!out-buffer

Paging stdout output in IPython

南笙酒味 提交于 2020-01-03 10:07:12
问题 Is it possible in an (interactive) IPython session to pass the stdout output through a pager, like less ? If so, how? For example, in In [1]: from some_module import function_that_prints_a_lot In [2]: function_that_prints_a_lot() ... everything scrolls away ... I would like to page through the stdout output of function_that_prints_a_lot . Another example: In [1]: %run script_that_prints_a_lot.py I've looked through IPython magic commands but didn't find any solution. 回答1: As discussed in chat

Why does writing to stdout in console append the number of characters written, in Python 3?

点点圈 提交于 2020-01-03 09:30:10
问题 I was just playing around with sys.stdout.write() in a Python console when I noticed that this gives some strange output. For every write() call the number of characters written, passed to the function respectively gets append to the output in console. >>> sys.stdout.write('foo bar') for example results in foo bar7 being printed out. Even passing an empty string results in an output of 0 . This really only happens in a Python console, but not when executing a file with the same statements.

Logging Python stdout to File… with active stdout (backspacing/updating)

笑着哭i 提交于 2020-01-03 05:38:33
问题 Ok, so using this example, I'm logging my stdout to a file as well as sending it to the terminal. But when I look at the log file, the backspaces are not processed, but printed along with the output. Any way I could log the "final" state of stdout of a python script? 回答1: Here is a solution that takes the basic class from the answer you linked and adds some regex handling for \r and \b : import sys import re class Logger(object): def __init__(self, filename="Default.log"): self.terminal = sys

System2 to call Python2 and Python3 inside R

佐手、 提交于 2020-01-03 02:30:36
问题 I want to execute python with R but > system2('python2', args = c('-c', 'print', 'hello'), stdout = TRUE) [1] "" prints "" instead of hello with python2. Then again > system2('python3', args = c('-c', 'print("hello")'), stdout = TRUE, stderr = TRUE) sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `'python3' -c print("hello") 2>&1' character(0) attr(,"status") [1] 2 Warning message: running command ''python3' -c print("hello") 2>&1' had status 2 prints a lot of warnings.

C++ print value of a pointer

十年热恋 提交于 2020-01-02 06:21:51
问题 I have an array of double pointers, but every time I try do print one of the values the address gets printed. How do I print the actual value? cout << arr[i] ? cout << &arr[i] ? they both print the address Does anyone know? 回答1: If it's really an array of (initialized) double pointers, i.e.: double *arr[] = ... // Initialize individual values all you need is: cout << *arr[i]; 回答2: cout << *(arr[i]) will print the value. 回答3: cout << *(arr[i]); 回答4: If "arr" is declared as double* arr[..];

stdin, stdout and stderr are shared between?

做~自己de王妃 提交于 2020-01-02 06:09:10
问题 I am trying to understand the behavior of the three streams - stdout , stdin and stderr . I couldn't get the answer from any textbook, so I came here. I know that these three are stored in file descriptor table with file descriptors 0 (stdin), 1 (stdout) and 2 (stderr). I am also aware that these are not merely file descriptors but I/O streams which can be redirected. Ok, so how about sharing? Consider the three cases: When a fork() is called : The child process and parent process shares file

How to limit the size of subprocess stdout and stderr in python

限于喜欢 提交于 2020-01-02 05:57:46
问题 I need to run applications submitted by users. My code looks like: def run_app(app_path): inp = open("app.in", "r") otp = open("app.out", "w") return subprocess.call(app_path, stdout=otp, stdin=inp) Now since I have no control over what users will submit, I want to restrict the size of the output of the application. Other things like trying to access unauthorized system resources and abusing of CPU cycles are being restricted by apparmor rule enforcement. The maximum time allowed to run is

How to limit the size of subprocess stdout and stderr in python

霸气de小男生 提交于 2020-01-02 05:57:12
问题 I need to run applications submitted by users. My code looks like: def run_app(app_path): inp = open("app.in", "r") otp = open("app.out", "w") return subprocess.call(app_path, stdout=otp, stdin=inp) Now since I have no control over what users will submit, I want to restrict the size of the output of the application. Other things like trying to access unauthorized system resources and abusing of CPU cycles are being restricted by apparmor rule enforcement. The maximum time allowed to run is