"Cannot Execute Binary File" When Trying to Run a Shell Script on Linux

cannot execute binary file when trying to run a shell script on linux

chmod -x removes execution permission from a file. Do this:

chmod +x path/to/mynewshell.sh

And run it with

/path/to/mynewshell.sh

As the error report says, you script is not actually a script, it's a binary file.

Cannot execute binary file with bash command

Just remove the bash on the last line of your script:

"${path}/Main"

Don't forget to make it executable.

chmod +x script.sh

It worked for me:

./script.sh hostname 80
Hello from Bash script..
Hostname:hostname
Port:80
Listing contents:
. .. Main main.cpp script.sh
Launching cpp executable:
Current path:/tmp/test
Hello World

Cannot execute binary file when calling its whole path

You cannot use . (or its effective alias, source) with binaries.

. / source is intended for executing shell code in the context of the current shell.

Binaries can only run in a child process, so you invoke them directly:

/usr/bin/bison

exec also creates a new process, but it replaces the current shell.

Shell complains 'cannot execute binary file'

"sed" isn't a shell script, so you don't execute it with sh. Just type sed ...args... not sh sed ...args...

cannot execute binary file on 64bit system

You can't execute this file with sh because this is not a shell script.

Execute it directly instead:

./AAAAAAA.bin

Simple bash commands fails, cannot execute binary file

It looks like when you're spawning the child process, you're actually trying to run the "file" command, not a shell script, so bash is barking at you.

It would be equivalent to typing this on the command line: "bash file".

You'll want to write a shell script and pass that as the parameter to the bash process.

So, write a script called "do_something.sh" and then run your code with ['do_something.sh'] as the parameter to bash rather than ['file']:

var process = spawn('bash', ['do_something.sh']);

system2( bash , ls ) - cannot execute binary file

Ok - this does the trick

system2("bash", input = "ls")

so instead of args = ... as with the powershell command one needs (or more interestingly sometimes 'can') use the input = ... parameter with bash

OR as mentioned in the comments by @oguzismail this will also work

system2("bash", "-c ls") 

as well as pointed out by @Christoph

system2("ls") 

also works sometimes (ie in some RStudio[?] setups it will not return results in some it will).

But I have come to notice that different combinations of R-versions with different RStudio versions [or more probably Locales] will not always behave consistently of course also depending on the availability of bash commands like ls (more generally /usr/bin) being on the PATH or not.

So choose what suits u best!

sudo throw error cannot execute binary file exec format error

Ok so I manage to fix it, here is what I've done,

login to root with su,
remove the alter version of sudo with: apt-get remove sudo:amd64
reinstall the correct version: apt-get install sudo
exit root mode and try it gain, now it works.

thanks

Getting the error: bash: (program): cannot execute binary file: Exec format error, on both 32-bit and 64-bit Windows

As indicated by file, your program is a Linux application so you can't run it on Windows. See

  • Why does a linux compiled program not work on Windows
  • Why won't Windows EXE files work on Linux?
  • Why do you need to recompile C/C++ for each OS?

Mingw is not an environment for running Linux executables, it's just a compiler that compiles POSIX code into native Windows binaries. Neither is Cygwin, which is a reimplementation of POSIX system calls in Windows, and Cygwin binaries are also native Windows binaries with a dependency on Cygwin DLLs. Read this if you want to know their differences. Bash is a shell and isn't a platform to execute files either. Only the runtime platform (OS or something like JVM or .NET CLR VM) can run programs and a shell is just a tool to interact with the OS

So you must run Linux programs in a Linux environment like a Linux machine or WSL1/2. Since the program is 32-bit, you can only run it in Linux or WSL2

Since you have the source code you can also compile the code with mingw or cygwin and run on Windows



Related Topics



Leave a reply



Submit