Hi Ian, Yes of course, here is the program. I am trying to use the os/exec package to call powershell then a script which is script.ps1. I have the script.ps1 in the same folder as main.go
package main import ( "fmt" "os" "os/exec" ) func main() { cmdName := "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" out, err := exec.Command("cmdName", script.ps1).Output() if err != nil { fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err) } fmt.Println(string(out)) } On Tuesday, October 27, 2020 at 7:34:47 PM UTC+3 Ian Lance Taylor wrote: > On Tue, Oct 27, 2020 at 9:25 AM Uzair Ally <mua...@gmail.com> wrote: > > > > I am getting the following error when I try to call a powershell script > from go. > > > > undefined: script > > > > Here is the code: > > > > cmdName := > "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" > > out, err := exec.Command("cmdName", script.ps1).Output() > > if err != nil { > > fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err) > > > > > > It looks like go doesn't recognize the powershell script. How do I > resolve this error? Any help or guidance will be appreciated. > > Your code fragment refers to a variable named "script". Where is that > variable defined? > > Can you show us a complete self-contained program, not just a code > fragment? > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f3495403-5969-4d8b-9e00-8024266392f1n%40googlegroups.com.