How to return the output of program in a variable?

后端 未结 4 412
轮回少年
轮回少年 2021-01-03 05:14

Can any one tell me how to return the output of a program in a variable from command line?

var = ./a.out params

I am trying to get the outp

4条回答
  •  情歌与酒
    2021-01-03 05:56

    To complement the answer from rasen, to get the variable from inside your program to the external environment, you need to print it to stdout.

    Using the syntax provided in the other answer simply takes all output from stdout and puts it in the shell environment variable var.

提交回复
热议问题