Hello,
I wonder if anyone can help with calling external shell script in c++. Basically, in the shellscript, I want to pass src, dst, md5. If the src's md5 matches md5 given, it will be link to the dst, if ln fails, copy src to dst. If success, return 0, if fails, return 1.
I tried both system, and execvp(fork) to work on it. As execvp never returns, so it cannot tell whether the shell script successfully performs or not. Even there is permission deny for copy, it always returns success. I switch to system, it works well in a single thread case (test many time in sandbox). However, my code is also involves multi-thread, many time, I got system return -1 (fork fails) even it successfully performs shell script. (The advanced linux programming book does not recommend system().)
Any suggestion on how to call a shell script to get its correct return value? Or I should get rid of shell script and code everything in c++.
Thank you
|