2

When i execute : /bin/sh -xe node -v I get the error : node: node: cannot execute binary file

Please suggest what I need to do to resolve this error.

When i execute below commands:

file /bin/bash Output :/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

file node node: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

3
  • I just learnt a lot about "cannot execute binary file" which is mostly caused by an incompatible binary. It doesn't look like this in your case. Hmm... Dumb question: Does your node file has executable (aka x) permissions? Commented Jun 14, 2017 at 10:27
  • Yes it has when i execute without bash it .. and directly type #node -v i get the required output: #node -v v8.1.0 Commented Jun 14, 2017 at 10:58
  • I could reproduce your problem even in cygwin. I just found out that I can run a self-compiled binary in cygwin's bash (e.g. $ ./test-int.exe) but I cannot when I call it this way: $ bash ./test-int.exe getting exactly your error. 1st guess: I have to provide full path but this didn't help. I'm still trying to find out what happens... Commented Jun 14, 2017 at 11:06

1 Answer 1

1

Out of curiosity, I played a little bit in my cygwin and got this (for me surprising) result:

$ cat >test-int.c <<EOF
> #include <stdio.h>
> 
> int main(int argc, char **argv)
> {
>   printf("sizeof (128): %u\n", sizeof (128));
>   printf("sizeof (4294967296): %u\n", sizeof (4294967296));
>   printf("sizeof (281474976710656): %u\n", sizeof (281474976710656));
>   return 0;
> }
> EOF

$ gcc -std=c11 -o test-int test-int.c

$ ./test-int 
sizeof (128): 4
sizeof (4294967296): 8
sizeof (281474976710656): 8

$ bash -xe ./test-int
./test-int: ./test-int: cannot execute binary file

$

After some searching I found it. Actually, you and me stumbled into the same trap...

According to man bash (close to the top):

If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands.

Having learnt this, I tried:

$ bash -c ./test-int
sizeof (128): 4
sizeof (4294967296): 8
sizeof (281474976710656): 8

$ bash -xec ./test-int
+ ./test-int
sizeof (128): 4
sizeof (4294967296): 8
sizeof (281474976710656): 8

$

Update:

I just realized another trap – the command line arguments. The following sample illustrates this:

$ cat >test-arg.c <<EOF
> #include <stdio.h>             
> 
> int main(int argc, char **argv)
> {
>   for (int i = 0; i < argc; ++i) printf("argv[%d]: '%s'\n", i, argv[i]);
>   return 0;
> }
> EOF

$ gcc -std=c11 -o test-arg test-arg.c

$ ./test-arg arg1 arg2 arg3
argv[0]: './test-arg'
argv[1]: 'arg1'
argv[2]: 'arg2'
argv[3]: 'arg3'

$ bash -c ./test-arg arg1 arg2 arg3
argv[0]: './test-arg'

$ 

So, what? The arguments are lost!

$ bash -xec ./test-arg arg1 arg2 arg3
+ ./test-arg
argv[0]: './test-arg'

$

This time, I found the solution without consulting the man bash:

$ bash -xec "./test-arg arg1 arg2 arg3"
+ ./test-arg arg1 arg2 arg3
argv[0]: './test-arg'
argv[1]: 'arg1'
argv[2]: 'arg2'
argv[3]: 'arg3'

$

To make it one call, the command and the arguments have to be "quoted together".

Sign up to request clarification or add additional context in comments.

5 Comments

Did you test it with your node application? test-int.exe is something I did my-self. (I should edit the answer appropriately.)
Yes I tested with my node application only on linux .. It enter bash shell and is asking for arguments.. like below: /bin/bash -xec /usr/local/bin/node /u03/node_modules/tslint/bin/tslint --format --out result.json + /usr/local/bin/node > > >
May be, it's worth to edit your question and adding this as update. Please, copy the output of shell as well. (Please, don't forget to format the code pieces with the {} button in the toolbar.)
As you can see in my sample, the -x causes debug output + ./test-int. Does something like this appear in your case?
I guess I found the 2nd problem also. Please, see my update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.