-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcallmethod.c
More file actions
55 lines (47 loc) · 1.25 KB
/
callmethod.c
File metadata and controls
55 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <memory.h>
#include <unistd.h>
int main( int argc, char ** argv )
{
/* create the pipe */
int pfd[2];
char buffer[BUFSIZ+1];
char * parmList[]= //{"ls","-l",NULL};
{"/usr/bin/ffmpeg", "-f","video4linux2","-s","640x480","-r","15","-i","/dev/video0","-vcodec","mjpeg","-f","avi","out.avi",NULL};
if (pipe(pfd) == -1)
{
printf("pipe failed\n");
return 1;
}
/* create the child */
int pid;
if ((pid = fork()) < 0)
{
printf("fork failed\n");
return 2;
}
if (pid == 0)
{
/* child */
close(pfd[0]); /* close the unused read side */
dup2(pfd[1], 1); /* connect the write side with stdout */
close(pfd[1]); /* close the write side */
/* execute the process (wc command) */
execvp("ffmpeg", parmList);
printf("ls failed"); /* if execlp returns, it's an error */
return 3;
}
else
{
/* parent */
close(pfd[1]); /* close the unused write side */
while (read(pfd[0], buffer, BUFSIZ) != 0)
{
printf("parent reads ");
}
close(pfd[0]); /* close the read side */
/* execute the process (ls command) */
return 4;
}
return 0;
}