My Goland的运行器(运行/调试配置)在os.Args[0]中使用/private/var/folders/7b/50mzg8x17q55rxfg3b0kpj88xcm2lx/T。我知道os.Args[0]是我的程序的路径,但是我可以把os.Args[0]作为我在Goland runner中的工作目录吗?
P.S.正确设置编辑配置中的工作目录
发布于 2019-09-09 13:13:50
我知道os.Args是我的程序的路径,但是我可以在Goland runner中使用os.Args作为我的工作目录吗?
不,您不能将os.Args[0]设置为工作目录,因为正如您正确识别的那样,它用于在磁盘上定位您的程序。
您可以进行两项更改:
os.Args[0],并开始使用os.Getwd()来获取工作目录。然后,您可以通过Run | Edit Configurations... | <name of the run configuration> | Working Directory参数编辑Run Configuration。Run | Edit Configurations... | <name of the run configuration> | Output directory,让集成开发环境运行编译器,并将可执行文件放在需要的任何位置。如果您需要对所有将来的运行配置进行这些更改,请编辑Run | Edit Configurations... | Templates | Go Build或Go Test并更改Working Directory或Output Directory字段。不会更改现有的Run Configurations。
https://stackoverflow.com/questions/57846169
复制相似问题