【发布时间】:2016-10-27 14:51:38
【问题描述】:
我在一个文件中有以下因子代码:
IN: set-work-dir
USING: shell ;
CONSTANT: work-dir "/code" ! I also tried "c:/code" and "c:\\code"--same error
work-dir cd
当我尝试从 factor 运行脚本时,出现此错误:
C:\>/usr/bin/factor/factor /usr/bin/factor/work/set-work-dir.factor
Generic word absolute-path does not define a method for the fixnum class.
Dispatching on object: 47
(U) Quotation: [ c-to-factor => ]
Word: c-to-factor
(U) Quotation: [ [ (get-catchstack) push ] dip call => (get-catchstack) pop* ]
(O) Word: command-line-startup
(O) Word: run-script
(O) Word: set-current-directory
(O) Method: M\ object absolute-path
(O) Word: no-method
(O) Method: M\ object throw
(U) Quotation: [
OBJ-CURRENT-THREAD special-object error-thread set-global
current-continuation => error-continuation set-global
[ original-error set-global ] [ rethrow ] bi
]
如果我有USING: io.files.private 而不是USING: shell ;,我可以让它运行,但在脚本运行之外不会保留目录更改。我假设使用 shell 会导致目录更改持续存在——我意识到这可能是一个错误的假设。如何编写脚本来更改目录并使目录更改在脚本之外持续存在?
Windows 7(是的,我知道 Windows 上的目录分隔符通常是 \,我也尝试过 '\'。但 / 实际上也适用于 Windows。除了路径在我使用 io 时有效。文件。私人)。
因子 0.98 x86.64(1788,heads/master-e187d63d3c,2016 年 10 月 18 日星期二 02:14:22) [Microsoft Visual C++ 190023506] 在 Windows 上
【问题讨论】:
-
这是底层操作系统的设计,不是Factor的缺点。子进程无法更改父进程的 CWD,在 Windows 中、Linux 中以及可能大多数操作系统中都没有。可能有一些黑客可以工作,但最好的办法是从批处理脚本中调用您的 Factor 程序,在退出时返回目录并让脚本更改 WD。在 Windows 中,我认为 .bat 或 .cmd 文件默认在同一个 shell 中运行。对于 Linux(我认为是 PowerShell)则相反,您必须指定您想要相同的 shell。
标签: shell factor-lang