简体   繁体   English

Makefile和命令行行为不同

[英]Makefile and command line different behaviour

I am currently working on a bigger project where i want to test executable file with few different codes as input. 我目前正在做一个更大的项目,我想用很少的不同代码作为输入来测试可执行文件。
I call it like this ./test < code1 and after command echo $? 我这样称呼它./test < code1并在命令后echo $? , it shows last returned value [0, 1, 2, ..] ,它显示最后返回的值[0,1,2,..]

I wanted to automate is, so i created call in makefile like this : 我想自动化,所以我在makefile创建了如下调用:

#makefile 
[...]
test : 
    ./test < code1 
    @echo $$?
    ./test < code2 
    @echo $$?
    [...]

[...]

So i can call make test . 所以我可以打电话给make test

When program returns 0 as success, everything works fine. 当程序成功返回0时,一切正常。 But when program has to return something else than 0, it shows me this : 但是,当程序必须返回非0的值时,它将显示以下内容:

./test < code3
Makefile:19: recipe for target 'test' failed
make: *** [test[ Error 2

Weird thing is, when i try to call program with code which made it crash in command line like : 奇怪的是,当我尝试使用导致其在命令行中崩溃的代码调用程序时:

./test < code3; echo $?  

It works perfectly and shows me last exit status ( for exapmle 3 ). 它运行完美,并向我显示了最后一个退出状态(例如3)。
I am confused now, because i thought it should work the same. 我现在很困惑,因为我认为它应该同样起作用。 Can someone help me out? 有人可以帮我吗?
Thank you! 谢谢!

See this answer: https://stackoverflow.com/a/41452754/939557 看到这个答案: https : //stackoverflow.com/a/41452754/939557

You need to put the echo into the same logical line as your test invocation: 您需要将echo置于与测试调用相同的逻辑行中:

test : 
        ./test < code1; echo $$?
        ./test < code2; echo $$?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM