【问题标题】:Getting different paths in Red language用 Red 语言获取不同的路径
【发布时间】:2026-01-17 09:20:02
【问题描述】:

我正在尝试用红色语言获得不同的路径。如果我 cd 到 /myfolder 并运行以下命令:

/myfolder$ /path/to/red.exe /path/to/myscript.red

如何从脚本中的代码中获取这 3 条路径?

我试过了:

system/options/path        ; Gives path/to/myscript
system/script/path         ; Gives none
call/output "pwd" outstr   ; Gives path/to/myscript
what-dir                   ; Gives path/to/myscript

我只能走一条路。如何获取 red.exe 的路径和当前工作目录的路径(红色语言 - 不是 Rebol)?

注意:这与我在 What-dir reporting own directory as current directory in Rebol 上关于 Rebol 的问题有关

【问题讨论】:

    标签: path rebol red


    【解决方案1】:

    在 Rebol (2 & 3) 中,您可以通过以下方式获得这三个路径:

    system/options/boot    ;; /path/to/red.exe
    system/options/path    ;; /myfolder
    system/script/path     ;; /path/to/myscript.red
    

    此时只有红色的 system/options/boot 与 Rebol 在此处所做的匹配。

    【讨论】:

      【解决方案2】:

      从 GUI 控制台:

      boot             string!       {C:\ProgramData\Red\gui-console-2017-11-30-4300.exe}
      home             none!         none
      path             file!         %/C/ProgramData/Red/
      script           none!         none
      cache            file!         %/C/ProgramData/Red/
      

      来自 cli:

      boot             string!       "C:\ProgramData\Red\console-2017-11-30-4430.
      home             none!         none
      path             file!         %/C/Users/Old%20Man/desktop/
      script           none!         none
      cache            file!         %/C/ProgramData/Red/
      

      使用 GUI 控制台:

      system/options/boot   ; Red binary
      system/options/path   ; current dir
      system/options/cache  ; Red default dir "home"
      

      system/options/boot 是 string!,因此您必须将其转换为:

      to-red-file system/options/boot
      

      【讨论】: