Hi Ian,

Thanks for your response!
Yeah I'm only getting the  error "cmdName declared but not used"  when I 
add script.ps1 in double quotes. If I remove the double quotes from 
script.ps1 then the only error I see is undefined: script.
The variable cmdName is set to call powershell.exe from it's path on the 
OS. I am then using that variable in out,err to run exec.Command, calling 
the first argument which is cmdName (the powershell process), and the 
second argument is set to call the powershell script (script.ps1). This 
works if I add one powershell command as the second argument, but what I am 
trying to do here is call an external script. 
I know Go is not a scripting language but I am trying to wrap the 
powershell script in a "simple" Go program to create an exe. 


On Tuesday, October 27, 2020 at 8:40:58 PM UTC+3 Ian Lance Taylor wrote:

> On Tue, Oct 27, 2020 at 10:27 AM Uzair Ally <mua...@gmail.com> wrote: 
> > 
> > 
> > If I add script.ps1 in double quotes and try to run, it tells me cmdName 
> declared but no used. 
> > Yes, the script is named script.ps1. The script is not a variable. 
>
> Your program has basic issues with using the Go language. I recommend 
> that you take a look at the Go tour (https://tour.golang.org) or other 
> Go documentation to learn how to use the language correctly. 
>
> You are getting the error "cmdName declared but not used" because you 
> have declared cmdName but you have not used it. You have a string 
> "cmdName", but that is a string, not a reference to the variable. The 
> Go language is not a scripting language. 
>
> Ian 
>
>
>
> > On Tuesday, October 27, 2020 at 8:22:14 PM UTC+3 Marvin Renich wrote: 
> >> 
> >> * Uzair Ally <mua...@gmail.com> [201027 12:25]: 
> >> > Hi, 
> >> > 
> >> > 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() 
> >> 
> >> Perhaps you what you intended was: 
> >> out, err := exec.Command("cmdName", "script.ps1").Output() 
> >> 
> >> Is your script named script.ps1 or is script a variable with a field 
> >> named ps1 containing the name of the script? 
> >> 
> >> > 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. 
> >> 
> >> ...Marvin 
> >> 
> > -- 
> > 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...@googlegroups.com. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/7868522a-17b1-429e-8ebc-bbcb7c678bbdn%40googlegroups.com.
>  
>
>

-- 
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/2f9ce91c-54bb-45c7-bdf6-3e27df57aaefn%40googlegroups.com.

Reply via email to