FAQ
How do i detect if its Windows or Linux or Mac then is it 32-bit or 64-bit?
I only getting the OS name

code:
package main

//import "os/exec"
//import "syscall"
import "runtime"
import "fmt"

func main() {

        fmt.Println(runtime.GOOS) // windows

/*
cmd := exec.Command(cmd, arg)
err := cmd.Start()
if err != nil {
println("Failed", err)
}
*/

}

--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dmitry Vyukov at Jan 27, 2014 at 4:01 pm
    There is also runtime.GOARCH
    If you are interested only in bitness, then you can use unsafe.Sizeof(uintptr)

    On Mon, Jan 27, 2014 at 9:36 AM, SProgrammer wrote:
    How do i detect if its Windows or Linux or Mac then is it 32-bit or 64-bit?
    I only getting the OS name

    code:
    package main

    //import "os/exec"
    //import "syscall"
    import "runtime"
    import "fmt"

    func main() {

    fmt.Println(runtime.GOOS) // windows

    /*
    cmd := exec.Command(cmd, arg)
    err := cmd.Start()
    if err != nil {
    println("Failed", err)
    }
    */

    }

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Martin Schnabel at Jan 27, 2014 at 5:51 pm

    On 01/27/2014 05:00 PM, Dmitry Vyukov wrote:
    There is also runtime.GOARCH
    If you are interested only in bitness, then you can use unsafe.Sizeof(uintptr)
    or you can do it without package unsafe:

    const wordsize = 32 << (^uint(0) >> 32 & 1)

    http://play.golang.org/p/aJ9384H4Yg

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Minux at Jan 28, 2014 at 12:02 am

    On Mon, Jan 27, 2014 at 12:50 PM, Martin Schnabel wrote:
    On 01/27/2014 05:00 PM, Dmitry Vyukov wrote:

    There is also runtime.GOARCH
    If you are interested only in bitness, then you can use
    unsafe.Sizeof(uintptr)
    or you can do it without package unsafe:

    const wordsize = 32 << (^uint(0) >> 32 & 1)

    http://play.golang.org/p/aJ9384H4Yg
    The result on playground is wrong. Technically the playground is 64-bit,
    e.g. the instructions are for amd64, but for some obscure reasons, int,
    uintptr and unsafe.Pointer are 32-bit.
    (the GOOS is amd64p32)

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brad Fitzpatrick at Jan 28, 2014 at 2:25 am
    On Mon, Jan 27, 2014 at 4:01 PM, minux wrote:
    On Mon, Jan 27, 2014 at 12:50 PM, Martin Schnabel wrote:
    On 01/27/2014 05:00 PM, Dmitry Vyukov wrote:

    There is also runtime.GOARCH
    If you are interested only in bitness, then you can use
    unsafe.Sizeof(uintptr)
    or you can do it without package unsafe:

    const wordsize = 32 << (^uint(0) >> 32 & 1)

    http://play.golang.org/p/aJ9384H4Yg
    The result on playground is wrong. Technically the playground is 64-bit,
    e.g. the instructions are for amd64, but for some obscure reasons, int,
    uintptr and unsafe.Pointer are 32-bit.
    (the GOOS is amd64p32)
    It's correct. Native Client's pointers are 32-bits, even if the instruction
    set is amd64.

    http://www.chromium.org/nativeclient/design-documents/native-client-application-binary-interface/data-representation

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Minux at Jan 28, 2014 at 2:43 am

    On Mon, Jan 27, 2014 at 9:25 PM, Brad Fitzpatrick wrote:
    On Mon, Jan 27, 2014 at 4:01 PM, minux wrote:

    On Mon, Jan 27, 2014 at 12:50 PM, Martin Schnabel wrote:
    On 01/27/2014 05:00 PM, Dmitry Vyukov wrote:

    There is also runtime.GOARCH
    If you are interested only in bitness, then you can use
    unsafe.Sizeof(uintptr)
    or you can do it without package unsafe:

    const wordsize = 32 << (^uint(0) >> 32 & 1)

    http://play.golang.org/p/aJ9384H4Yg
    The result on playground is wrong. Technically the playground is 64-bit,
    e.g. the instructions are for amd64, but for some obscure reasons, int,
    uintptr and unsafe.Pointer are 32-bit.
    (the GOOS is amd64p32)
    It's correct. Native Client's pointers are 32-bits, even if the
    instruction set is amd64.


    http://www.chromium.org/nativeclient/design-documents/native-client-application-binary-interface/data-representation
    Well, yes. what I mean is that it doesn't necessarily detect the word size
    of the underlying
    machine (which is 64-bit even though pointer is 32-bit for sandboxing
    purposes)

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Minux at Jan 28, 2014 at 12:04 am

    On Mon, Jan 27, 2014 at 11:00 AM, Dmitry Vyukov wrote:

    There is also runtime.GOARCH
    If you are interested only in bitness, then you can use
    unsafe.Sizeof(uintptr)
    The OP asks for checking the OS if it's 32/64 bits. so we can't use the
    runtime.GOARCH or unsafe.Sizeof(uintptr).

    The correct way will be to use the same routine in in cmd/dist/unix.c
    that determines the GOHOSTARCH.

    http://golang.org/src/cmd/dist/unix.c#L669

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 27, '14 at 3:45p
activeJan 28, '14 at 2:43a
posts7
users5
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase