0
ahrouhi's Avatar, Join Date: Mar 2011
Go4Expert Member
Quote:
while(){
system("d:\\ffmpeg -i ..........);//i want the program stop here and let ffmpeg.exe get to its end and then run the next line
IndexFunction();
}
In the symbolic above loop we have two main process:
1-"ffmpeg" process: ffmpeg is a program which has been called by "system" and controled by O.S. This program take a long time to get end.
2-"indexFunction" process which is a function defined by me in C code. This function calculate indexes according to an algorithm and take a long time to be completed to.

my question is that when the above program is running, when it pass the ffmpeg to O.S to run the ffmpeg.exe, then before that ffmpeg process get to its end, the program run the function "IndexingFunction" or no?
I am interested to start "IndexFunction" when the "ffmpeg" finishes its process. How can i do this? How can i halt the running whole program when it get to "system(d:\ffmpeg...) and when this line finished then continue the rest of the program lne? (something like interpreters)
0
ahrouhi's Avatar, Join Date: Mar 2011
Go4Expert Member
In another word I need a function in C that runs an external executive program (like "system" command) which return a distinct value when the executive program process has been ended.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
I thought system did both of those.
0
ahrouhi's Avatar, Join Date: Mar 2011
Go4Expert Member
In IEEE reference i have read the below text about system() function in C:
Quote:
The system() function shall ignore the SIGINT and SIGQUIT signals, and shall block the SIGCHLD signal, while waiting for the command to terminate. If this might cause the application to miss a signal that would have killed it, then the application should examine the return value from system() and take whatever action is appropriate to the application if the command terminated due to receipt of a signal.
And also it mentioned that the child process should be terminated when called by system():
Quote:
The system() function shall not return until the child process has terminated.
As can be seen , you are right , but i am right too. The child process should be terminated before continuing the main process. But if an error signal or interrupt happen, then seems that program may loose something in this case. Thats why i want to find a robust method for calling a child process.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Does your program use signals?
0
ahrouhi's Avatar, Join Date: Mar 2011
Go4Expert Member
Signal Errors are important for my programs.
BTW how can i implement a formatted string which converted from an integer in c or c++?
i want something like printf("%3d",number) but i need to strcat the string to another string
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
system() is pretty robust; what *exactly* doesn't work as you want if you use it? Specify something more exact than "the program may lose something" - what exactly DOES it lose under exactly what circumstances? I've no way of knowing what "more robust" call is going to work if I don't know exactly what system() can't cope with.

printf is sufficient and you can do a combined printf and strcat in one easy operation under the right circumstances:
Code:
Untested! My compiler is in the middle of something else ATM.
char str[128];
int n=15;
strcpy(str,"The number is ");
sprintf(str+strlen(str),"%d",n); **WARNING** CHECK FOR BUFFER OVERFLOW **WARNING**
puts(str); // output should be: The number is 15
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Heck, or even
Code:
char str[128];
sprintf(str,"The number is %d",n);
0
ahrouhi's Avatar, Join Date: Mar 2011
Go4Expert Member
Thanks. What i want for converting int to string or char*, actually is a formatted string. I need to show in three character string which if the number is less than 3 character, it filled with zero at left. like:
string 001 for 1
string 023 for 23
string 431 for 431
ant i want it in the middle of another string. like:
strcat(str1, int-2-string);
whats your suggestion? I have seen it is very easy in C sharp but in C or C++ it seems i should write some lines for this formatted output. am i right?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Code:
sprintf(str,"The number-->%03d<<--rebmun ehT\n",27);
RTFM!