call external shell script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ellennolan
    New Member
    • Oct 2007
    • 2

    #1

    call external shell script

    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
  • ellennolan
    New Member
    • Oct 2007
    • 2

    #2
    anyone knows the answer? system vs execvp? thank you!

    Comment

    • ruskalym
      New Member
      • Sep 2007
      • 65

      #3
      Have a look at waitpid() and at associated macros such as WEXITSTATUS().

      Comment

      Working...