如何在Shell脚本之外保留更改目录?

时间:2016-10-27 14:51:38

标签: shell factor-lang

我在文件中有以下因子代码:

IN: set-work-dir
USING: shell ;
CONSTANT: work-dir "/code" ! I also tried "c:/code" and "c:\\code"--same error
work-dir cd 

当我尝试从因子I运行脚本时出现此错误:

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: shell ;我有USING: io.files.private而不是脚本运行之外保留目录更改,我可以运行它。我假设使用shell会导致目录更改仍然存在 - 我意识到这可能是一个不好的假设。如何编写脚本来更改目录并使目录更改在脚本之外保持不变?

Windows 7(是的,我知道Windows上的目录分隔符通常是\,我也尝试过了。但/实际上也适用于Windows 。当我使用io.files.private时,路径也可以工作。

因子0.98 x86.64(1788,heads / master-e187d63d3c,Tue Oct 18 02:14:22 2016) Windows上的[Microsoft Visual C ++ 190023506]

1 个答案:

答案 0 :(得分:1)

cd作品存在于两个词汇中。 cd将调用哪一个USING:取决于您的身份shell。如果shell:cd,则会io.files.private调用io.files.private:cd,然后调用io.files.private:cd。您当然也可以使用完全限定名称。

虽然用户代码不应使用.private字,因为词汇的名称以set-current-directory结尾,表示该字不是公共接口的一部分。而是使用IN: scratchpad "/tmp" set-current-directory IN: scratchpad "." absolute-path . "/tmp"

{{1}}

因子进程终止后,更改将不会保留。