stdout

Why does python keep buffering stdout even when flushing and using -u?

情到浓时终转凉″ 提交于 2019-12-06 07:18:28
问题 $ cat script.py import sys for line in sys.stdin: sys.stdout.write(line) sys.stdout.flush() $ cat script.py - | python -u script.py The output is right but it only starts printing once I hit Ctrl-D whereas the following starts printing right away : $ cat script.py - | cat which led me to think that the buffering does not come from cat. I managed to get it working by doing : for line in iter(sys.stdin.readline, ""): as explained here : Streaming pipes in Python, but I don't understand why the

Getting the entire output from subprocess.Popen

℡╲_俬逩灬. 提交于 2019-12-06 06:04:35
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 that command from an interactive Python shell it looks like this >>> args = ['cscript', '%USERPROFILE%\

Streaming stdout to a web page

房东的猫 提交于 2019-12-06 04:41:38
This seems like it should be a really simple thing to achieve, unfortunately web development was never my strong point. I have a bunch of scripts, and I would like to launch them from a webpage and see the realtime stdout text on the page. Some of the scripts take a long time to run so the normal single response isn't good enough (I have this working already). As far as I can see, my options are stdout to a file, and periodically (every couple of seconds) send a request from the client and respond with the contents of this file. Chunked HTTP responses? I'm not sure if this is what they are

How to process stdin to stdout in php?

天涯浪子 提交于 2019-12-06 04:13:00
问题 I'm trying to write a simple php script to take in data from stdin , process it, then write it to stdout . I know that PHP is probably not the best language for this kind of thing, but there is existing functionality that I need. I've tried <?php $file = file_get_contents("php://stdin", "r"); echo $file; ?> but it doesn't work. I'm invoking it like this: echo -e "\ndata\n" | php script.php | cat . and get no error messages. The script I'm trying to build will actually be part of a larger

bash redirect to /dev/stdout: Not a directory

社会主义新天地 提交于 2019-12-06 04:07:05
问题 I recently upgraded from CentOS 5.8 (with GNU bash 3.2.25) to CentOS 6.5 (with GNU bash 4.1.2). A command that used to work with CentOS 5.8 no longer works with CentOS 6.5. It is a silly example with an easy workaround, but I am trying to understand what is going on underneath the bash hood that is causing the different behavior. Maybe it is a new bug in bash 4.1.2 or an old bug that was fixed and the new behavior is expected? CentOS 5.8: (echo "hi" > /dev/stdout) > test.txt echo $? 0 cat

wget hangs with -r and -O -

佐手、 提交于 2019-12-06 03:52:58
This is a VERY strange wget behavior. I'm on debian 7.2. wget -r -O - www.blankwebsite.com hangs forever. And I mean it hangs , it isn't searching through the internet, I can verify it with a strace . If I do this: while read R do wget -r -O - www.blankwebsite.com done < smallfile with smallfile containing a single line, the command exits in a few seconds. I tried also with wget -r -O - localhost/test.html with an empty test.html file, same results. To me, it sounds like a bug. Everything runs fine changing -O - with -O myfile or removing -r . I used -O - because I was passing output to grep .

python subprocess hide stdout and wait it to complete

旧时模样 提交于 2019-12-06 03:39:59
问题 I have this code: def method_a(self): command_line = 'somtoolbox GrowingSOM ' + som_prop_path subprocess.Popen(shlex.split(command_line)) ...... def method_b(self): ..... .... and like you all see, method_a has a subprocess that is calling the somtoolbox program. But this program have a long stdout, and I want to hide it. I tried: subprocess.Popen(shlex.split(command_line), stdout=subprocess.PIPE) But it returned this sentence: cat: record error: Broked Pipe (this is a translation of the

Reassigning global $stdout to console - ruby

心已入冬 提交于 2019-12-06 03:39:58
问题 I am trying to set $stdout to write to a file temporarily and then back to a file. test.rb : old_stdout = $stdout $stdout.reopen("mytestfile.out",'w+') puts "this goes in mytestfile" $stdout= old_stdout puts "this should be on the console" $stdout.reopen("mytestfile1.out",'w+') puts "this goes in mytestfile1:" $stdout = old_stdout puts "this should be back on the console" Here is the output. ruby test.rb => no output on the console cat mytestfile.out this goes in mytestfile this should be on

Running an interactive program from Ruby

不问归期 提交于 2019-12-06 02:31:50
I am trying to run gnuplot from ruby (not using an external gem) and parsing its textual output also. I tried IO.popen , PTY.spawn and Open3.popen3 but whenever I try to get the output it just "hangs" -I guess waiting for more output to come. I feel like its somehow done using Thread.new but I couldn't find the correct way to implement it. Anyone know how it is done? I guess this is what you want: require 'pty' require 'expect' PTY.spawn('gnuplot') do |input, output, pid| str = input.expect(/gnuplot>/) puts str output.puts "mlqksdf" str = input.expect(/gnuplot>/) puts str output.puts "exit"

Communicate with subprocess without waiting for the subprocess to terminate on windows

瘦欲@ 提交于 2019-12-06 02:15:26
问题 I have a simple echoprocess.py: import sys while True: data = sys.stdin.read() sys.stdout.write("Here is the data: " + str(data)) And a parentprocess.py from subprocess import Popen, PIPE proc = Popen(["C:/python27/python.exe", "echoprocess.py"], stdin = PIPE, sdtout = PIPE) proc.stdin.write("hello") print proc.stdout.read() This just hangs until echoprocess.py is terminated. I want to communicate with this subprocess multiple times without having to restart it again. Is this kind of