FAQ
Hello,

How can i change directory of exec command on Windows ?
This code working byt this is go app working directory:

result, _ := exec.Command("cmd", "/C", "git", "status").Output()

When I want to change path then result always is empty string

result, _ := exec.Command("cmd", "/C", "cd", "C:\\Folder\\example", "git", "status").Output()


In php on Linux i use exec command like this:

exec('cd /var/www/example/ && git status', $res);

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Paweł Bednarski at Feb 3, 2015 at 1:35 pm
    Hi,

    Try changing working directory with func Chdir() from os package.

    Best regards,
    Pawel Bednarski

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Marvin Renich at Feb 3, 2015 at 1:38 pm

    * robert.jablecki@gmail.com [150203 08:30]:
    Hello,

    How can i change directory of exec command on Windows ?
    This code working byt this is go app working directory:

    result, _ := exec.Command("cmd", "/C", "git", "status").Output()

    When I want to change path then result always is empty string

    result, _ := exec.Command("cmd", "/C", "cd", "C:\\Folder\\example", "git", "status").Output()
    var cmd = exec.Command("cmd", "/C", "git", "status")
    cmd.Dir = "/your/starting/dir"
    var result, err = cmd.Output()
    if err != nil {
         // handle the error
    }

    ...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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 3, '15 at 1:29p
activeFeb 3, '15 at 1:38p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase