Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
bashどのようにstderrを変数にキャプチャしますか?
bashスクリプト内でこのようなことをしたい
sh -c path/myExcecutable-bin 2>&1 =MYVARIABLE
stderror出力を変数に送信するにはどうすればよいですか?
stdout と stderr変数の両方を保存するには:
stdout
stderr
MYVARIABLE="$(path/myExcecutable-bin 2>&1)"
これにより、stdoutとstderrが同じ変数にインターリーブされることに注意してください。
変数だけ に保存するには:stderr
MYVARIABLE="$(path/myExcecutable-bin 2>&1 > /dev/null)"