By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,822 Members | 729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,822 IT Pros & Developers. It's quick & easy.

call external shell script

P: 2
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
Oct 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: 2
anyone knows the answer? system vs execvp? thank you!
Oct 26 '07 #2

ruskalym
P: 65
Have a look at waitpid() and at associated macros such as WEXITSTATUS().
Oct 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.