I want to pass the exit code of an OS command to the URL. I'm using gin but I'm open to any way.
I just want to pass the err to the HTTP response.
As of yet, I'm not able to find an example for putting os output into HTTP response example so I've come here in the hope someone knows.
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"os/exec"
)
func Homepage(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Hello World"
}
}
func Powershell(c *gin.Context) {
// Run this powershell program from Go.
cmd := exec.Command("powershell","-file","C:\\temp\\test.ps1")
// Wait for the Powershell program to exit.
err := cmd.Run()
//fmt.Println("Finished:", err)}
c.JSON(200, gin.H{
"Message": "This is the PowerShell exit code not the script exit code",
"Finished:", err
}
func main() {
fmt.Println("hello world")
r := gin.Default()
r.GET("/", Homepage)
r.GET("/app", Powershell)
r.Run()
}
So far everything I've tried just error on the get /app