Error with bash script "exit code 126"

122,240

Solution 1

The problem was in the wrong script. I give a revised script, which logs have been added:

echo "Checking files in ${SOURCE_ROOT}"
CPD_DIR=${PROJECT_DIR}/CPD
JARS_DIR=${PROJECT_DIR}/CPD
FULL_PATH_TO_CPD_XML_OUTPUT=${PROJECT_DIR}/cpd-output.xml
OBJC_JAR_LIBRARY=${JARS_DIR}/ObjCLanguage-0.0.5-SNAPSHOT.jar

echo [DEBUG] CPD_DIR = ${CPD_DIR}
echo [DEBUG] JARS_DIR = ${JARS_DIR}
echo [DEBUG] FULL_PATH_TO_CPD_XML_OUTPUT = ${FULL_PATH_TO_CPD_XML_OUTPUT}
echo [DEBUG] OBJC_JAR_LIBRARY = ${OBJC_JAR_LIBRARY}
echo [DEBUG] SOURCE_ROOT = ${SOURCE_ROOT}

# Running CPD
java -classpath "${OBJC_JAR_LIBRARY}:${JARS_DIR}/pmd.jar" net.sourceforge.pmd.cpd.CPD --minimum-tokens 200 --files "${SOURCE_ROOT}" -v --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > "${FULL_PATH_TO_CPD_XML_OUTPUT}"

CPD_EXECUTABLE="${CPD_DIR}/CPDObjective-C"
if [ ! -f "${CPD_EXECUTABLE}" ];
then
echo "CPD executable file is not found: " ${CPD_EXECUTABLE}
fi
echo "Running ${CPD_EXECUTABLE} -cpd-xml ${FULL_PATH_TO_CPD_XML_OUTPUT}"
"${CPD_EXECUTABLE}" -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

Here is source code of sample Copy-Paste-Detect

Solution 2

126 for “command not executable"

# Running self :)
${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

It looks like $BUILT_PRODUCTS_DIR} is not executable Can you update with the value of this var please

Solution 3

The error may also be caused due to inadequate "Permissions" to run the Shell. I got:- bash: /home/XXX.sh: Permission denied exit-status: 126
On fixing the permissions on shell script, the issue got fixed.

Solution 4

Like the error message in the pastebin says, the value of ${BUILT_PRODUCTS_DIR} is a directory (line 314). It doesn't make any sense to attempt to execute a directory, so it appears that the build script is broken or corrupted.

By the by, are the setenv commands part of the script as well? This is typically a csh command, not a sh or bash command. Executing a directory doesn't make sense under tcsh either, though, as far as I am aware.

Share:
122,240

Related videos on Youtube

alexmorhun
Author by

alexmorhun

iOS developer, PM. Interested in game development. Sometimes web sites.

Updated on October 07, 2020

Comments

  • alexmorhun
    alexmorhun over 3 years

    I want integrate CPD (Copy-Paste-Detection) to my iOS project. I read about it here and here.

    To automatically determine CopyPaste in the code I'm using bash script:

    echo "Checking files in ${SOURCE_ROOT}"
    JARS_DIR=${PROJECT_DIR}/CPD
    FULL_PATH_TO_CPD_XML_OUTPUT=${PROJECT_DIR}/cpd-output.xml
    
    # Running CPD
    java -classpath "${JARS_DIR}/ObjCLanguage-0.0.5-SNAPSHOT.jar:${JARS_DIR}/pmd.jar" net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files "${SOURCE_ROOT}" -v --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > "${FULL_PATH_TO_CPD_XML_OUTPUT}"
    
    # Running self :)
    ${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"
    

    That code create cpd-output.xml file. But take me an error at compile time "Command /bin/sh failed with exit code 126". Here is log copy http://pastebin.com/359k1Wni I took the code from this example project Error is going then I comment this string:

    ${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"
    

    I tried to find what ever information about this error, but found only a few of these problems without answers. I'm not know anything about bash scripting. I will be happy with any advice. Thank you for your attention.

    P.S. Author of following the script written:

    In order to integrate XCode and the CPD, we will add to the Build Phases target with the project, Run Script phase, conventionally consisting of several parts: Actually calling cpd Parsing cpd-output.xml Output in the "right format"

  • alexmorhun
    alexmorhun about 12 years
    Unfortunately, I'm not know anything about bash scripting. I added the words of the author of this script.
  • Chris
    Chris about 12 years
    Essentially your application does not have permission from the bash shell to run $BUILT_PRODUCTS_DIR}. How to do that will depend on the code you copied from the project. I will try to take a look at it, but I don't know Objective C (assuming thats what its in). I will update if i figure it out.
  • carbocation
    carbocation over 5 years
    I ran into this issue while trying to build for Docker. Thanks for your fix.
  • tripleee
    tripleee over 4 years
    If you have any files named D or E or B or U or G, the unquoted [DEBUG] will be interpreted as a wildcard and expanded into a list of those files (also depending on some shell options), The obvious fix is to quote your strings. See also stackoverflow.com/questions/10067266/…
  • Neil McGuigan
    Neil McGuigan about 4 years
    chmod +x foo.sh to allow execution