-1

I have an exe, which takes 2 .csv files as input. As below:

cSplittinglines.exe srcdir\file.csv destdir\file.csv

How can I execute this .exe using a shell script so that the directory from which the script is run has no impact on the location of the exe. aka avoid hard coding the exe path. Below is the script I am working on.

#!/bin/sh
STARTTIME=`date '+%Y%m%d.%H%M%S'`

LOGFILE=${ERRDIR}/${0}.${STARTTIME}

SplitDir=$1

LyxlamDir=$2

echolog ()
{
    echo $*
    echo $* >> ${LOGFILE}
}

    for file in "${SplitDir}"/*; do
    if [ -d "$file" ]; then continue; fi
    extension=${file##*.}

    if [ "$extension" = "csv" ]
    then    
        cSplittingLines.exe "$file" "${LyxlamDir}"
        mv "$file" "${SplitDir}/old"

    fi
done

closed as unclear what you're asking by Rui F Ribeiro, Michael Homer, Ipor Sircer, Archemar, Christopher Jan 24 at 16:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You seem to have a strange mix of Windows executable and paths and Unix shell script. What is the context you're working in for that to happen? – Michael Homer Jan 24 at 4:16
  • yes,its a windows exe. We always use shell script for windows exe,which works fine,so as to pass the parameters for the exe. We have a MKS tool which also takes shell script in windows. – Raghav manchale Jan 24 at 4:20
  • 3
    That's probably a relevant element for you to include in the question, and anything else about the environment that might help someone to answer. – Michael Homer Jan 24 at 4:22
  • 1
    What is going wrong? Show us (in the question). “Something goes wrong some where”, is not useful, and will not help us spot an error. – ctrl-alt-delor Jan 24 at 8:00
  • 1
    Try adding an echo about to run cSplittingLines.exe to the script, that way you can see if it gets to this bit of the script. Alternatively turn on shell tracing. – ctrl-alt-delor Jan 24 at 8:03
2

Just put the exe on your $PATH (That is what it is for) (%PATH% on Windows)

mv cSplittingLines.exe /bin/

or

echo "export PATH=\"\$PATH:/path/to/exe\"" >> ~/.bashrc

Also https://www.shellcheck.net said;

SC2006: Use $(...) notation instead of legacy backticked `...`.
SC2086: Double quote to prevent globbing and word splitting.
  • Or specify directory and name, in script. – ctrl-alt-delor Jan 24 at 8:04
  • 1
    @ctrl-alt-delor I assume by " I don't want it as hard coded" he ment he did not want that. Maybe he will clarify. – user1133275 Jan 24 at 8:23
  • 1
    ya.. the directory and file path should not be hard coded. – Raghav manchale Jan 24 at 12:19
  • What about "$(dirname $0)/…/cSplittingLines.exe" replace the … with the relative path. – ctrl-alt-delor Jan 24 at 16:13
  • @ctrl-alt-delor yah any relative path would work if the 2 were kept relative to eachother but the ambiguity of the question led me to the more robust solution. – user1133275 Jan 24 at 17:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.