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

当我执行: / bin / sh -xe节点-v我得到错误:node:node:不能执行二进制文件

请build议我需要做些什么来解决这个错误。

当我执行下面的命令:

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

GNU / Linux 2.6.18的文件节点节点:ELF 64位LSB可执行文件,x86-64版本1(GNU / Linux),dynamic链接(使用共享库),不会被去除

出于好奇,我在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 $ 

经过一番search,我发现它。 其实你和我都陷入了同样的陷阱

根据man bash (接近顶部):

如果参数在选项处理之后仍然存在,并且没有提供-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' $ 

这一次,我发现解决scheme没有咨询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' $ 

为了使它成为一个呼叫 ,命令论据必须“引用在一起”。