I want to run a cpp executable from my git for windows bash. I do not understand why I can run it with ./Main but I can't run it with bash Main or bash Main.exe. In the latter cases, I'm getting an error:
cannot execute binary file
main.cpp
#include<iostream>
int main()
{
std::cout<<"Hello World";
return 0;
}
script.sh
echo "Hello from Bash script.."
echo "Hostname:${1}"
echo "Port:${2}"
echo "Listing contents:"
ls -a
echo "Launching cpp executable:"
path=$(pwd)
echo "Current path:${path}"
bash "${path}/Main"
To compile the C++ code, I'm using: g++ -o Main main.cpp.
What is the problem? Can someone explain please?
.cpp?bashalready told you : it can't execute binary files.bash filenameyou're telling bash to execute the shell commands found in the file: it is expected to be a text file containing a shell script.bash -c executableFilewhich spawns a bash shell to run the specified command, but you still need to provide the path to it, just like./executableFile