【问题标题】:Can the jshell command `/open` work relatively to the folder containing the script, instead of the working directory?jshell 命令 `/open` 可以相对于包含脚本的文件夹而不是工作目录工作吗?
【发布时间】:2017-10-30 23:29:45
【问题描述】:

我在同一文件夹/path/folder 中有两个 jshell 脚本 script.jshcommons.jsh

script.jsh

/open commons.jsh

commons.jsh

System.out.println("commons.jsh loaded")
  • 如果我在/path/folder 中,我可以运行jshell script.jsh,它运行良好
  • 如果我在/path/folder/subfolder 中运行jshell ../script.jsh,它会以File 'commons.jsh' for '/open' is not found 失败。

有什么解决办法吗?换句话说,jshell命令/open是否可以相对于包含脚本的文件夹而不是工作目录工作?

这里针对 bash 提出了类似的问题:Bash: How _best_ to include other scripts?

Edit1:使问题更精确

Edit2:这是我在写这个问题时正在处理的真正的 jshell 脚本,第一个可用的脚本在这里 https://framagit.org/Gwendal/helpful-scripts/blob/3e8118970a6a412dfe0f199e93545745d890243f/jshell/dia2pdf.jsh 打开包含辅助方法https://framagit.org/Gwendal/helpful-scripts/blob/3e8118970a6a412dfe0f199e93545745d890243f/jshell/commons.jsh

【问题讨论】:

  • 仔细考虑了这个问题并将其限制在此评论中。恕我直言,用例归结为 Interactive Shell(!=REPL) 的需要。使用从 Y 位置执行的 X 脚本的特定位置的主要区别。不要否认可以支持此类用户输入的事实,但需要针对REPL to provide that 进行评估。不过,可能有用的是用 .sh 脚本 eq 包装 .jsh

标签: java java-9 jshell


【解决方案1】:

好吧,我研究这个已经有一段时间了……

我知道的唯一方法是添加 "commons.jsh" 文件的完整路径。 它有效。

【讨论】:

  • 不完全是,完整路径不是相对的,但至少这回答了问题。
猜你喜欢
  • 2015-02-12
  • 1970-01-01
  • 2015-07-31
  • 2020-02-26
  • 1970-01-01
  • 2016-03-04
  • 2012-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多