get command output in pipe, C for Linux

Is this it? NAME popen, pclose – process I/O SYNOPSIS #include <stdio.h> FILE *popen(const char *command, const char *type); int pclose(FILE *stream); DESCRIPTION The popen() function opens a process by creating a pipe, forking, and invoking the shell. Since a pipe is by definition unidirectional, the type argument may specify only reading or writing, not … Read more

Implementing pipe in C

This does virtually no error checking, but why so complicated? int main (int argc, char ** argv) { int i; for( i=1; i<argc-1; i++) { int pd[2]; pipe(pd); if (!fork()) { dup2(pd[1], 1); // remap output back to parent execlp(argv[i], argv[i], NULL); perror(“exec”); abort(); } // remap output from previous child to input dup2(pd[0], 0); … Read more

Pipe raw OpenCV images to FFmpeg

Took a bunch of fiddling but I figured it out using the FFmpeg rawvideo demuxer: python capture.py | ffmpeg -f rawvideo -pixel_format bgr24 -video_size 640×480 -framerate 30 -i – foo.avi Since there is no header in raw video specifying the assumed video parameters, the user must specify them in order to be able to decode … Read more

How does a pipe work in Linux?

If you want to redirect the output of one program into the input of another, just use a simple pipeline: program1 arg arg | program2 arg arg If you want to save the output of program1 into a file and pipe it into program2, you can use tee(1): program1 arg arg | tee output-file | … Read more

running a command line containing Pipes and displaying result to STDOUT

Use a subprocess.PIPE, as explained in the subprocess docs section “Replacing shell pipeline”: import subprocess p1 = subprocess.Popen([“cat”, “file.log”], stdout=subprocess.PIPE) p2 = subprocess.Popen([“tail”, “-1”], stdin=p1.stdout, stdout=subprocess.PIPE) p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. output,err = p2.communicate() Or, using the sh module, piping becomes composition of functions: import sh output = sh.tail(sh.cat(‘file.log’), … Read more