dsgd4654674 2016-08-27 20:25 采纳率: 0%
浏览 351
已采纳

os.Chdir(“ / tmp”)在Go中工作异常

I used Macbook. I tried to use os.Chdir("/tmp") but the outcome was /private/tmp. Following is my code:

package main

import (
  "fmt"
  "os"
)

func main() {
  s, _ := os.Getwd()
  fmt.Println(s)

  if err := os.Chdir("/tmp"); err != nil {
    panic(err)
  }
  s, _ = os.Getwd()
  fmt.Println(s)

}

And the output is:

➜  test   go run main.go
/Users/willy/test
/private/tmp

Why?

  • 写回答

1条回答 默认 最新

  • dongzhenjian5195 2016-08-28 07:49
    关注

    As chown in this Apple thread

    On OS X, /tmp is an alias for /private/tmp.

    $ ls -ale / | grep -i tmp
    
    lrwxr-xr-x@    1 root  wheel        11 Aug 30  2009 tmp -> private/tmp
    
    $
    

    And a golang syscall.Chdir() would follow that symlink.
    So the final path is expected on a Mac OS platform.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度