W
W
webinside2019-03-20 23:16:09
C++ / C#
webinside, 2019-03-20 23:16:09

Running a binary from a C program?

I'm writing a program for raspberry in C (WiringPi)
The camera is connected via CSI, access via raspistill
in the console everything works:
$ raspistill -o image.jpg -w 800 -h 600 -t 200- OK
with the iron in order.
in the program through

system("raspistill -o image.jpg -w 800 -h 600 -t 200");

everything works too, but the program, which is understandable, hangs before the command is executed.
How to put the execution of raspistill as a process so that the program does not hang?
I try through exec, it doesn't work. Mistake. How to pass parameters correctly?
exec("raspistill", ???);
exec("raspistill -o image.jpg -w 800 -h 600 -t 200", ???);

Or do you need it differently, C I know very badly.
Help =(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Cheremisin, 2019-03-20
@webinside

In order for the program to be executed in parallel, you need to create a copy of your process using fork() or vfork() and execute exec() in the child process. Parameters are passed as an array of strings or individual parameters with a terminating null..

...
if (fork() == 0) { // разделиться
    execl("raspistill", "raspistill", "-o", "image.jpg", "-w" ,"800", "-h", "600", "-t", "200" , "echo", "this is", (char *) 0); // заменить процесс
     perror("exec one failed"); // если что-то пошло не так, выдать ошибку
     exit(1); // здесь завершаем новый процесс, если не отработал execl
}
// здесь продолжение старого процесса 
...

W
wisgest, 2019-03-27
@wisgest

Maybe there are answers in this topic: How to run programs in Linux separately from the terminal?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question