My previous reply was sent to Ian. Sorry.
The point I don't understand is "os.Args".
I think the parameter here is the name of my program. So like "program.exe".

Can support be added to Golang so that these variables can be accessed from in-program sources such as "os.Environ"?

Unfortunately I don't know the whole structure of go compiler. I don't know what problems this can bring.

But not every Golang program works on the console. Some of them are GUIs and it is not possible to access them from the console.

That would be a great thing.


On 17/12/2020 00:28, Ian Lance Taylor wrote:
On Wed, Dec 16, 2020 at 8:49 AM Sean <s.tolstoyev...@gmail.com> wrote:
hi all,
i have a project I have to work with CGo. I want to disable some
controls as they are not good enough right now.
It works when I write "set godebug=cgocheck=0" on Windows in console.
However, this is a GUI program. Console should not open.

I tried this with "os.Setenv". I define it in "func init" it doesn't work.

Something like this:

func init() {
      os.Setenv("godebug", "cgocheck=0")
}

What should I do?
At present I believe that the best you can do is something like, in
main (untested):

     if os.Getenv("GODEBUG") == "" {
         cmd := exec.Command(os.Args[0], os.Args[1:]...)
         cmd.Env = append(os.Environ(), "GODEBUG=cgocheck=0")
         if err := cmd.Run(); err != nil {
             os.Exit(1)
         }
         os.Exit(0)
     }

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/c014f7e0-58bb-77e4-d7fc-123443a7f77a%40gmail.com.

Reply via email to