stdout

stdin stdout python: how to reuse the same input file twice?

余生颓废 提交于 2019-12-02 07:17:34
I am quite new to Python and even newer to stdin stdout method. Nevertheless I need to make my script usable for UNIX commands, in order to make it possible for example to process 2 input files at once with my script. This script works perfectly well with command line arguments: newlist = [] def f1() .... def f2(input_file): vol_id = sys.argv[3] for line in input_file: if ... : line = line.replace('abc','def') line = line.replace('id', 'id'+vol_id) .... newlist.append(line) return newlist def main(): if len(sys.argv) < 4: print 'usage: ./myscript.py [file_in... file_out... volume_id]' sys.exit

Streaming an MP3 on stdout to Jplayer using PHP

℡╲_俬逩灬. 提交于 2019-12-02 07:11:15
I'm initializing jplayer with the following parameters: $jplayer.jPlayer('setMedia',{ mp3: data.audioMP3, oga: data.audioOGA }); Assume that data.autdioMP3 (and it's OGA counterpart) are paths to a php script, for example: 'http://myserver.local/playaudio.php?songID=99&format=mp3' Where I am struggling is with playaudio.php . I would like to read the MP3 file and stream it to jplayer without revealing the path to the audio (this is why I am not initializing jplayer with a path to the audio file). Something like (taken partially from the example for readfile at php docs): <?php $if ($validUser

Redirecting in C++

不问归期 提交于 2019-12-02 05:54:16
#include <iostream> #include <fstream> using namespace std; void foo(){ streambuf *psbuf; ofstream filestr; filestr.open ("test.txt"); psbuf = filestr.rdbuf(); cout.rdbuf(psbuf); } int main () { foo(); cout << "This is written to the file"; return 0; } Does cout write to the given file? If not, is there a way to do it without sending the variables to foo, like new ? update : I can't use a solution that uses class or uses global so plz can some give me solution that use new. Also passing the from main to foo streambuf *psbuf; ofstream filestr; should work right? I am trying to do this but its

Is there a way to use locked standard input and output in a constructor to live as long as the struct you're constructing?

余生长醉 提交于 2019-12-02 05:41:45
I'm building a PromptSet that can ask a series of questions in a row. For testing reasons, it allows you to pass a reader and writer instead of using stdin & stdout directly. Because stdin and stdout are the common use case, I would like to create a default "constructor" that allows the user to produce a PromptSet<StdinLock, StdoutLock> without needing any parameters. Here's the code so far: use std::io::{self, BufRead, StdinLock, StdoutLock, Write}; pub struct PromptSet<R, W> where R: BufRead, W: Write, { pub reader: R, pub writer: W, } impl<R, W> PromptSet<R, W> where R: BufRead, W: Write, {

Python carriage return not working

早过忘川 提交于 2019-12-02 05:32:58
问题 I have a long-running script that loops over rows in a database. Every so often I'd like it to print how many rows it's processed, but without creating a new line each time. This is essentially what I have: import sys mystr = "{} rows complete\r" for i in range(0, 100): if i % 10 == 0: sys.stdout.write(mystr.format(i)) sys.stdout.flush() When I run this (on Python 2.7.5 64-bit, Windows) I get: 0 rows complete 10 rows complete 20 rows complete ... 100 rows complete Can anyone think of why the

Execute a process and return its standard output in VC++

拥有回忆 提交于 2019-12-02 04:44:31
What's the easiest way to execute a process, wait for it to finish, and then return its standard output as a string? Kinda like backtics in Perl. Not looking for a cross platform thing. I just need the quickest solution for VC++. Any ideas? WinAPI solution: You have to create process (see CreateProcess) with redirected input (hStdInput field in STARTUPINFO structure) and output (hStdOutput) to your pipes (see CreatePipe), and then just read from the pipe (see ReadFile). hmm.. MSDN has this as an example: int main( void ) { char psBuffer[128]; FILE *pPipe; /* Run DIR so that it writes its

How to redirect stdout and stderr streams (Multiplatform)?

旧城冷巷雨未停 提交于 2019-12-02 04:15:39
问题 I'm writing GL application that uses external libs, which print errors to the console. I want to catch that and print in the in-game console. PS: Sorry, for my bad english.... 回答1: There are two basic approaches you could take to this: If the libraries all use std::cout for the IO you want to capture you can write your own basic_streambuf. You can then just call std::cout.rdbuf(mybufinst); to replace the streambuffer, for example using the std::basic_stringbuf : #include <sstream> #include

Stop a function from writing to stdout

杀马特。学长 韩版系。学妹 提交于 2019-12-02 04:11:13
I have this line in my code: writer = cv.CreateVideoWriter('video.avi', cv.CV_FOURCC('X','V','I','D'), 30 ,(480,800), 1) Which outputs to console this: Output #0, avi, to 'video.avi': Stream #0:0: Video: mpeg4, yuv420p, 480x800, q=2-31, 24576 kb/s, 90k tbn, 30 tbc I want to stop it from printing anything to stdout, but keep the possibility to output by myself something further in the code. How can I achieve this? I tried this, but it didn't worked. class NullStream: def write(self, text): pass sys.stdout = NullStream() sys.stderr = NullStream() print "hello" #This doesn't outputs #This

Get process output without blocking

被刻印的时光 ゝ 提交于 2019-12-02 02:35:49
I want to get a process' output ( Git.exe to be exact) and convert it to a String object. Previously sometimes my code was blocked. Then I figured out that it's because the process' ErrorStream has some output and I have to manually capture that (which I'm not interested in). I changed my code to this: public static String runProcess(String executable, String parameter) { try { String path = String.format("%s %s", executable, parameter); Process pr = Runtime.getRuntime().exec(path); // ignore errors StringWriter errors = new StringWriter(); IOUtils.copy(pr.getErrorStream(), errors);

Python carriage return not working

巧了我就是萌 提交于 2019-12-02 02:14:45
I have a long-running script that loops over rows in a database. Every so often I'd like it to print how many rows it's processed, but without creating a new line each time. This is essentially what I have: import sys mystr = "{} rows complete\r" for i in range(0, 100): if i % 10 == 0: sys.stdout.write(mystr.format(i)) sys.stdout.flush() When I run this (on Python 2.7.5 64-bit, Windows) I get: 0 rows complete 10 rows complete 20 rows complete ... 100 rows complete Can anyone think of why the carriage return isn't working? I've seen some similar questions here about Python and \r , but all the