Anyway to get return value of c program from command line?

前端 未结 2 1196
小鲜肉
小鲜肉 2020-12-28 12:47

I understand if I write a bash script I can get the return value, but is there anyway to get the return value without scripting, and just command line?

相关标签:
2条回答
  • 2020-12-28 13:30

    Yes, the same way you'd do in a Bash script. Run your program like this:

    ./your_program; echo $?
    
    0 讨论(0)
  • 2020-12-28 13:43

    In light of the invalidation of the previous answer (good point, Carl Norum), let me re-phrase my comment as an answer:

    BASH stores the return value of the previously run command in the variable $?. This is independent of the programming langauge used to write said command (the command can also be a shell internal).

    0 讨论(0)
提交回复
热议问题