0

I have go script main.go which I am calling it from shell script. main.go returns the response as below on success. I am looking to capture the return response in a variable from the same shell script I am calling main.go

Response from running 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

First response is when ran first file where there is no content to read and second response in when there is something in the file and it loaded in the table

I have tried something like

go run main.go > return_resp
echo $return_resp 

however it was not much of help

Shyam Bhimani
  • 1,310
  • 1
  • 22
  • 37
  • It's unclear from your description, what exactly you consider a response. Is it the standard output of a program? Or the standard error? Or both? – user1934428 Jul 13 '23 at 06:09
  • If I'm not mistaken, `> return_resp` creates a file with that name, and you (vainly) try to echo a env variable with the same name. – NotX Jul 13 '23 at 16:23

1 Answers1

5

You can try these

return_resp=$(go run main.go)
echo $return_resp

or

go run main.go > output.txt 2>&1
cat output.txt
PRATHEESH PC
  • 1,461
  • 1
  • 3
  • 15