正确设置工作路径
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 shell 的 cd 实用程序似乎是一个合适的解决方案。另一种方法是将
PWD
环境变量设置为带有符号链接的路径名,但这很丑陋,除非您让ProcessBuilder
自动为您完成此操作。请注意,如果
PWD
不是当前目录的绝对路径名,shell 会忽略它,而是向系统询问不带符号链接的绝对路径名。Using a shell's
cd
utility seems an appropriate solution. An alternative would be to set thePWD
environment variable to the pathname with symlinks, but this is ugly unless you getProcessBuilder
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.