I want to write a programme where I compile a C programme, and save it where BASH recognises programmes are (/usr/bin or somewhere).
For usage I want to run in the terminal
$ c_programme <file_input> | <programme_to_pipe_stdout>
I can see that with the popen() function I can use ffmpeg to process video:
FILE *pipein = popen("ffmpeg -i teapot.mp4 -f image2pipe -vcodec rawvideo -pix_fmt rgb24 -", "r");
FILE *pipeout = popen("ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s 1280x720 -r 25 -i - -f mp4 -q:v 50 -an -vcodec mpeg4 output.mp4", "w");
But in the above teapot.mp4 was already specified in the code, not input into the C programme when the programme was run in BASH. How can I make a variable in the C code which will read from the shell?
Similarly, I don't want to output to a file, I just want to output to stdout, so I can pipe it. How would I do this?
Thanks!
A C program can get the arguments passed to it on the command line by declaring
mainasint main(int argc, char *argv[]), after whichargv[0]refers to the name of the program,argv[1]is the first argument,argv[2]is the second, and so on up toargv[argc-1]. The end is also indicate byargv[argc]being a null pointer.For example, the output of this program:
when executed as
foo Argument1 Argument2is:Use
printf,puts, orputchar.