piping

Python capture all printed output

自闭症网瘾萝莉.ら 提交于 2019-12-05 16:36:18
问题 I am looking to write console based programs in python that can execute functions to perform generic tasks, pretty generic. Is it possible to capture everything written to the console by print calls in a function without needing to return a string, similar to how bash and the windows shell allow piping the output of a program to a text file, ie ipconfig>ipconfig.txt but doing this inside of a python program, where a function is called, everything that was printed to the console inside of that

crossfading a group of audio files with sox splice

和自甴很熟 提交于 2019-12-05 16:02:55
I am able to join and crossfade two audio files using SoX, like so: sox file1.wav file2.wav outfile.wav splice -q `soxi -D file1.wav`,0.5 where the soxi substitution is fetching the duration of file1 and 0.5 is the length of the cross-fade. I am now trying to extend this to an arbitrary number of files, in order to string them together with short crossfades in between. There would seem to be 2 approaches: piping and scripting. Sox has a -p option telling it to treat it's output as piped (instead of writing a file). But, with many input and arguments per command, it's not clear how that output

unsuccessful use of popen() in C?

女生的网名这么多〃 提交于 2019-12-05 14:02:37
I can run the following command xwd -root | xwdtopnm | pnmtojpeg > screen.jpg in a terminal under linux and it will produce a screenshot of my current screen. I try to do the following with the code: #include <stdio.h> #include <stdlib.h> int main() { FILE *fpipe; char *command="xwd -root | xwdtopnm | pnmtojpeg"; char line[256]; if ( !(fpipe = (FILE*)popen(command,"r")) ) { // If fpipe is NULL perror("Problems with pipe"); exit(1); } while ( fgets( line, sizeof line, fpipe)) { //printf("%s", line); puts(line); } pclose(fpipe); } then I compile and run the program ./popen > screen.jpg but the

Problem with piping commands in C

大憨熊 提交于 2019-12-05 01:31:32
I'm trying to create a simple shell in C for Unix. I've been able to do all the parsing of commands and execution, but I'm having a problem with piping. I think the problem is that I'm not hooking into the correct pipe for the input of the second command. For example, if I type "ls | wc", it will pause after the "wc" command, which I think is because its waiting for input. I think the problem is when I use dup2(reading[i],0), and its not hooking into the correct pipe. I know this is a bit of a broad question, but if there are any pointers I could get, I would appreciate it. Here is the code

PowerShell ForEach / Piping confusion

泄露秘密 提交于 2019-12-05 00:52:54
I am using the TFS PowerTools Cmdlets in PowerShell to try to get at some information about Changesets and related WorkItems from my server. I have boiled the problem down to behavior I don't understand and I am hoping it is not TFS specific (so someone out there might be able to explain the problem to me :) ) Here's the only command that I can get to work: Get-TfsItemHistory C:\myDir -recurse -stopafter 5 | % { Write-Host $_.WorkItems[0]["Title"] } It does what I expect - Get-TfsItemHistory returns a list of 5 ChangeSets, and it pipes those to a foreach that prints out the Title of the first

Piping data between threads with Java

隐身守侯 提交于 2019-12-04 11:51:15
问题 I am writing a multi-threaded application that mimics a movie theater. Each person involved is its own thread and concurrency must be done completely by semaphores. The only issue I am having is how to basically link threads so that they can communicate (via a pipe for instance). For instance: Customer[1] which is a thread, acquires a semaphore that lets it walk up to the Box Office. Now Customer[1] must tell the Box Office Agent that they want to see movie "X". Then BoxOfficeAgent[1] also a

CMD: piping ECHO to SET/ expanding variables in variables

為{幸葍}努か 提交于 2019-12-04 06:24:11
问题 %x:~12,3% Returns 3 characters starting at the 12:th character in x variable. What I have been trying to accomplish is using variables instead of 12 and 3 . Let's say y=12 and z=3 . Then, you can't use %x:~%y%,%z%% , because CMD will think %x:~% is a variable. What you can do is set var=%%x:~%y%,%z%%% . This will expand the inside variables y and z , but not x , so that the value of var is %x:~12,3% . The remaining task at hand now is to finally expand %x:~12,3% . I have been trying to append

Python capture all printed output

前提是你 提交于 2019-12-04 01:52:18
I am looking to write console based programs in python that can execute functions to perform generic tasks, pretty generic. Is it possible to capture everything written to the console by print calls in a function without needing to return a string, similar to how bash and the windows shell allow piping the output of a program to a text file, ie ipconfig>ipconfig.txt but doing this inside of a python program, where a function is called, everything that was printed to the console inside of that function is gathered as a list of strings, and then can be saved to a txt file of the users choice?

Piping data between threads with Java

亡梦爱人 提交于 2019-12-03 08:21:58
I am writing a multi-threaded application that mimics a movie theater. Each person involved is its own thread and concurrency must be done completely by semaphores. The only issue I am having is how to basically link threads so that they can communicate (via a pipe for instance). For instance: Customer[1] which is a thread, acquires a semaphore that lets it walk up to the Box Office. Now Customer[1] must tell the Box Office Agent that they want to see movie "X". Then BoxOfficeAgent[1] also a thread, must check to make sure the movie isn't full and either sell a ticket or tell Customer[1] to

CMD: piping ECHO to SET/ expanding variables in variables

跟風遠走 提交于 2019-12-02 10:01:18
%x:~12,3% Returns 3 characters starting at the 12:th character in x variable. What I have been trying to accomplish is using variables instead of 12 and 3 . Let's say y=12 and z=3 . Then, you can't use %x:~%y%,%z%% , because CMD will think %x:~% is a variable. What you can do is set var=%%x:~%y%,%z%%% . This will expand the inside variables y and z , but not x , so that the value of var is %x:~12,3% . The remaining task at hand now is to finally expand %x:~12,3% . I have been trying to append echo in the beginning so that var=echo %x:~12,3% . If at the commandline or in a batch file you now