我有 go 脚本 main.go,我从 shell 脚本中调用它。如果成功,main.go 将返回如下响应。我希望从我调用 main.go 的同一个 shell 脚本中捕获变量中的返回响应
运行 go run main.go 的响应
No content to read in :/labs/text/11/004/11-004_M0_1_arm_1.d78d350eef91f1e72d801e064a088cf80d3c840a-0023.txt
2023/07/13 04:46:52 /app/lab-processor/src/main.go:201 SLOW SQL >= 200ms
[1267.568ms] [rows:1] SELECT * FROM "pipeline1_2"."p_doc_pp_dates" WHERE filename LIKE '%11-004_M0_1_arm_1.d78d350eef91f1e72d801e064a088cf80d3c840a%' AND pagenumber = 38 ORDER BY begin desc LIMIT 1
Run Code Online (Sandbox Code Playgroud)
第一个响应是当运行第一个文件时没有内容可读取时,第二个响应是当文件中有内容并将其加载到表中时
我试过类似的东西
go run main.go > return_resp
echo $return_resp
Run Code Online (Sandbox Code Playgroud)
但这并没有多大帮助
你可以尝试这些
return_resp=$(go run main.go)
echo $return_resp
Run Code Online (Sandbox Code Playgroud)
或者
go run main.go > output.txt 2>&1
cat output.txt
Run Code Online (Sandbox Code Playgroud)