无法为节点命令执行二进制文件

时间:2017-06-14 10:02:30

标签: node.js linux bash

当我执行时: / bin / sh -xe node -v 我收到错误:node:node:无法执行二进制文件

请建议我需要采取哪些措施来解决此错误。

当我执行以下命令时:

file / bin / bash 输出:/ bin / bash:ELF 64位LSB可执行文件,x86-64,版本1(SYSV),动态链接(使用共享库),用于GNU / Linux 2.6.18,剥离

文件节点 node:ELF 64位LSB可执行文件,x86-64,版本1(GNU / Linux),动态链接(使用共享库),用于GNU / Linux 2.6.18,未剥离

1 个答案:

答案 0 :(得分:1)

出于好奇,我在我的cygwin中玩了一点,得到了这个(对我来说很惊讶)结果:

$ 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

$

经过一番搜索,我发现了它。实际上,你和我偶然发现了陷阱......

根据man bash(靠近顶部):

  

如果参数处理后仍然存在参数,则-c和-c都不存在   -s选项已被提供,第一个参数被假定为   包含shell命令的文件的名称

了解了这一点后,我尝试了:

$ 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

$

<强>更新

我刚刚意识到另一个陷阱 - 命令行参数。以下示例说明了这一点:

$ 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'

$ 

那么,什么?争论丢失了!

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

$

这一次,我在没有咨询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'

$

要进行一次通话,命令参数必须一起引用&#34;。

相关问题