stdout

Read console output of another program in Python

核能气质少年 提交于 2019-12-23 11:59:10
问题 There are two programs - parent.py and myscript.py, shown below. parent.py keeps printing messages in the console. And myscript.py needs access to what parent.py prints. parent.py: import time while 1: time.sleep(1) print "test" myscript.py: import subprocess p = None p = subprocess.Popen(['python', 'parent.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) for line in p.stdout: print line I want myscript.py to catch the output of parent.py dynamically. As it can be seen that parent.py

Redirecting of stdout in bash vs writing to file in c with fprintf (speed)

风流意气都作罢 提交于 2019-12-23 09:02:22
问题 I am wondering which option is basically quicker. What interests me the most is the mechanism of redirection. I suspect the file is opened at the start of the program ./program > file and is closed at the end. Hence every time a program outputs something it should be just written to a file, as simple as it sounds. Is it so? Then I guess both options should be comparable when it comes to speed. Or maybe it is more complicated process since the operating system has to perform more operations?

getting python script to print to terminal without returning as part of stdout

旧时模样 提交于 2019-12-23 08:30:12
问题 I'm trying to write a python script that returns a value which I can then pass in to a bash script. Thing is that I want a singe value returned in bash, but I want a few things printed to the terminal along the way. Here is an example script. Let's call it return5.py: #! /usr/bin/env python print "hi" sys.stdout.write(str(5)) what I want is to have this perform this way when I run it from the command line: ~:five=`./return5.py` hi ~:echo $five 5 but what I get is: ~:five=`./return5.py` ~:echo

Erlang read stdin write stdout

假装没事ソ 提交于 2019-12-23 07:01:10
问题 I'm trying to learn erlang through interviewstreet. I just learning the language now so I know almost nothing. I was wondering how to read from stdin and write to stdout. I want to write a simple program which writes "Hello World!" the number of times received in stdin. So with stdin input: 6 Write to stdout: Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Ideally I will read the stdin one line at a time (even though it's just one digit in this case) so I think I

Using mapConcurrently to read stdin, make HTTP calls and write to stdout in parallel

那年仲夏 提交于 2019-12-23 06:06:51
问题 I'm writing a program that reads multiple URLs (one per line) from standard input, slightly adapts them and makes HTTP requests for each of those multiple URLs in parallel. Responses are printed to standard output. Here's the code: {-# LANGUAGE OverloadedStrings #-} module Main where import Control.Monad import Network.Wreq import Control.Concurrent.MSem import Control.Concurrent.Async import Control.Concurrent (threadDelay) import qualified Data.Traversable as T main :: IO () main = void $

Sinatra 1.3 Streaming w/ Ruby stdout redirection

蹲街弑〆低调 提交于 2019-12-23 06:04:20
问题 I would like to use Sinatra's Streaming capability introduced in 1.3 coupled with some stdout redirection. It would basically be a live streaming output of a long running job. I looked into this question and the Sinatra streaming sample in the README. Running 1.8.7 on OSX: require 'stringio' require 'sinatra' $stdout.sync = true module Kernel def capture_stdout out = StringIO.new $stdout = out yield out ensure $stdout = STDOUT end end get '/' do stream do |out| out << "Part one of a three

Sinatra 1.3 Streaming w/ Ruby stdout redirection

一笑奈何 提交于 2019-12-23 06:03:04
问题 I would like to use Sinatra's Streaming capability introduced in 1.3 coupled with some stdout redirection. It would basically be a live streaming output of a long running job. I looked into this question and the Sinatra streaming sample in the README. Running 1.8.7 on OSX: require 'stringio' require 'sinatra' $stdout.sync = true module Kernel def capture_stdout out = StringIO.new $stdout = out yield out ensure $stdout = STDOUT end end get '/' do stream do |out| out << "Part one of a three

child process owning the file used to redirect the std output of its parent process

萝らか妹 提交于 2019-12-23 05:23:18
问题 Scenario I have a batch file a.bat which below contains statements A.exe >> a.txt Test.exe >> a.txt A.exe starts up another exe say b.exe (by _wpopen function) and returns. But after redirecting output of A.exe , ownership of a.txt seems to be transferred to b.exe. As test.exe cannot redirect its stdout to a.txt as b.exe is still running and still owns a.txt. B.exe runs indefinitely, cannot wait for it to stop. And also I cannot redirect the output to multiple files. As these exe executions

shell - keep writing to the same file[name] even if externally changed

半城伤御伤魂 提交于 2019-12-23 04:51:14
问题 There's a process, which should not be interrupted, and I need to capture the stdout from it. prg > debug.log I can't quite modify the way the process outputs its data, though I'm free to wrap its launch as I see fit. Background, piping the output to other commands, etc, that's all a fair game. The process, once started, must run till the end of times (and can't be blocked, say, waiting for a fifo to be emptied). The writing isn't very fast, and the file can be cut at arbitrary place, if it

Tcl/Tk - Memchan - fifo - how to rename fifo as stdout in a tcl/tk application which has Memchan statically linked?

吃可爱长大的小学妹 提交于 2019-12-23 04:45:14
问题 I cross posted this question on comp.lang.tcl. I am developing a Tcl/Tk application (call it rs ) and I want to redirect stdout and stderr to a text box in my Tcl/Tk application. I am using Memchan to achieve this (I statically linked Memchan into my application). But I am unable to rename the fifo channel I created as stderr . (The same thing holds true for stdout too) For example, in the following snippet, I am closing stderr and then opening fifo as stderr but fifo channel remains named as