我有一个地形文件:
terraform {
required_version = "1.3.5"
}
locals {
a = "foo"
b = "bar"
}
在 bash 终端中,我可以这样做:
$ echo "local.a" | terraform console
"foo"
$ echo "local.b" | terraform console
"bar"
现在我想做的是启动一个terraform console
在后台运行的进程并为其提供命令。
这就是我尝试过的(按照这个答案https://serverfault.com/a/815253):
$ mkfifo /tmp/srv-input
$ tail -f /tmp/srv-input | terraform console >>output.txt 2>&1 &
这会正确启动后台进程:
$ ps -ax | grep terraform
6030 pts/0 Sl 0:01 terraform console
如果我然后运行:
$ echo "local.a" > /tmp/srv-input
输出文件output.txt
为空。
$ cat output.txt
$
如果我运行:
$ echo "local.c" > /tmp/srv-input # invalid input
输出文件output.txt
包含(预期的)错误:
$ cat output.txt
╷
│ Error: Reference to undeclared local value
│
│ on <console-input> line 1:
│ (source code not available)
│
│ A local value with the name "c" has not been declared. Did you mean "a"?
╵
[1]+ Exit 1 tail -f /tmp/srv-input | terraform console >> output.txt 2>&1
为什么只有 stderr 被重定向到日志文件,而不是 stdout?