How to return the output of program in a variable?

后端 未结 4 422
轮回少年
轮回少年 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条回答
  •  猫巷女王i
    2021-01-03 05:56

    To save the program output to stdout in variable in Unix shell, regardless of language program wrote in, you can use something like this

    var=`./a.out params`
    

    or this

    var=$(./a.out params)
    

    Remember not to put spaces before or after the = operator.

提交回复
热议问题