Running a shell command from Ruby: capturing the output while displaying the output?

后端 未结 7 1439

I have a problem.

I want to run a ruby script from another ruby script and capture it\'s output information while letting it output to the screen too.

runner

7条回答
  •  清酒与你
    2021-02-10 02:51

    Have your script do its prompt output to stderr.

    echo "Enter something" >&2
    read answer
    echo "output that will be captured"
    

    This will be done for you if you use read -p to issue the prompt:

    read -p "Enter something" answer
    echo "output that will be captured"
    

提交回复
热议问题