Set output of a command as a variable (with pipes)

前端 未结 6 1118
花落未央
花落未央 2020-12-01 05:09

Can you redirect the output of a command to a variable with pipes?

I haven\'t tried much as I haven\'t been able to think of anything to try, but I have tried one me

6条回答
  •  甜味超标
    2020-12-01 05:32

    You can set the output to a temporary file and the read the data from the file after that you can delete the temporary file.

    echo %date%>temp.txt
    set /p myVarDate= < temp.txt
    echo Date is %myVarDate%
    del temp.txt
    

    In this variable myVarDate contains the output of command.

提交回复
热议问题