正确设置工作路径

发布于 2024-09-15 16:01:04 字数 1120 浏览 9 评论 0原文

ProcessBuilder pb = new ProcessBuilder("pwd");
pb.directory(new File("/server1/work/uz/rt/adapt/0/"));
Process s = pb.start();

我期望输出为 /server1/work/uz/rt/adapt/0/,但实际上是:

/work/uz/rt/adapt/0/

/work/uz/rt/adapt/0//server1/work/uz/rt/adapt/0/ 是等效的(安装在同一位置,/work/.. 是正确的路径,/server1/work/.. 是安装的路径) ,但我需要在 /server1/work/uz/rt/adapt/0/ 下工作,因为其他一些服务器只能通过该路径工作。

如何使 /server1/work/uz/rt/adapt/0/ 成为当前路径?

换句话说,

为什么公共 ProcessBuilder 目录(文件目录) 将目录转换为规范文件。如何使用绝对文件路径?

我还尝试了 hack soln'

        pb.directory(new File("/asr1/work/oguz/rt/adaptMLLR2/0/"){
             public File getCanonicalFile(){
                 return this.getAbsoluteFile();
             }
             public String getCanonicalPath() {
                 return this.getAbsolutePath();
             }

        });

,但效果不佳。

我通过在 bash 脚本中添加 cd /server1/.. 行解决了我的问题。并删除了 pd.directory(..) 行。但是这个问题(为什么我不能将 pd.directory(..) 与 AbsolutePath 一起使用)还没有得到解答......???

ProcessBuilder pb = new ProcessBuilder("pwd");
pb.directory(new File("/server1/work/uz/rt/adapt/0/"));
Process s = pb.start();

I expected the output to be /server1/work/uz/rt/adapt/0/, but instead it's:

/work/uz/rt/adapt/0/

/work/uz/rt/adapt/0/ and /server1/work/uz/rt/adapt/0/ are equivalent (mounted at the same place,/work/.. is correct path and /server1/work/.. is the mounted one ), but I need to work under /server1/work/uz/rt/adapt/0/ because some other servers only work through that path.

How can I make /server1/work/uz/rt/adapt/0/ the current path?

IN OTHER WORDS

why public ProcessBuilder directory(File directory)
converts directory into canonical File. How can I use absolute File Path??

I also tried the hack soln'

        pb.directory(new File("/asr1/work/oguz/rt/adaptMLLR2/0/"){
             public File getCanonicalFile(){
                 return this.getAbsoluteFile();
             }
             public String getCanonicalPath() {
                 return this.getAbsolutePath();
             }

        });

which didnt work as well.

I resolved my problem by adding cd /server1/.. line in to the bash script.. and deleted pd.directory(..) line. BUT this problem (why I cant use pd.directory(..) with absolutePath ) is not answered yet...???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄风 2024-09-22 16:01:04

使用 shell 的 cd 实用程序似乎是一个合适的解决方案。另一种方法是将 PWD 环境变量设置为带有符号链接的路径名,但这很丑陋,除非您让 ProcessBuilder 自动为您完成此操作。

请注意,如果 PWD 不是当前目录的绝对路径名,shell 会忽略它,而是向系统询问不带符号链接的绝对路径名。

Using a shell's cd utility seems an appropriate solution. An alternative would be to set the PWD environment variable to the pathname with symlinks, but this is ugly unless you get ProcessBuilder to do it for you automatically.

Note that shells ignore PWD if it is not an absolute pathname for the current directory, asking the system for a absolute pathname without symlinks instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文