問題描述
IntelijIDEA (Goland) 使用 /private/var/folders/ (IntelijIDEA (Goland) uses /private/var/folders/)
My Goland 的跑步者(運行/調試配置)在 os.Args[0]
中使用 /private/var/folders/7b/50mzg8x17q55rxfg3b0kpj88xcm2lx/T。我知道 os.Args[0]
是我的程序的路徑,但我可以將 os.Args[0]
作為我在 Goland runner 中的工作目錄嗎?
編輯配置中的PS工作目錄設置正確
參考解法
方法 1:
I know that os.Args[0] is the path to my program, but can I do os.Args[0] to be my working directory in Goland runner?
No, you cannot make os.Args[0]
to be the working directory, since as you correctly identified, it's used to locate your program on disk.
There are two changes you can make:
- change your code to stop relying on
os.Args[0]
and start usingos.Getwd()
to get the working directory. Then you can edit yourRun Configuration
viaRun | Edit Configurations... | <name of the run configuration> | Working Directory
parameter. - if you really want you binary to be in a certain directory, then you can go to
Run | Edit Configurations... | <name of the run configuration> | Output directory
to have the IDE run the compiler and place the executable wherever you need to.
If you need to make these changes for all future Run Configurations, then edit Run | Edit Configurations... | Templates | Go Build
, or Go Test
and change either the Working Directory
or the Output Directory
fields. Existing Run Configurations
will not be changed.