java exec 空格_路径名称上带有空格的Java Runtime Exec

我正在尝试运行一个OSPL命令,该命令是plutil,用于将某些plist转换为json格式。我在终端中使用的命令是

plutil -convert json -o - '/Users/chris/project/temp tutoral/project.plist'

路径名称带有白色间距的此命令在我的终端中可以很好地运行,并且我的终端用单引号(“)覆盖路径名,但是问题在于在Java

Runtime.getRuntime().exec(cmdStr)下面运行此命令是我编写的代码

public static void main(String args[]){

LinkedList output = new LinkedList();

String cmdStr = "plutil -convert json -o - /Users/chris/project/temp tutoral/project.plist";

//String cmdStr = " plutil -convert json -o - '/Users/chris/project/temp tutoral/project.plist'";

//String [] cmdStr ={ "plutil -convert json -o - ", "\"Users/chris/project/temp tutoral/project.plist\""};

Process p;

try {

p = Runtime.getRuntime().exec(cmdStr);

BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

String line = "";

while ((line = reader.readLine()) != null) {

output.add(line);

System.out.println(line);

}

} catch (Exception e) {

e.printStackTrace();

}

}

如果我运行此代码,它将给我一个错误

'Users/chris/project/temp: file does not exist or is not readable or is not a regular file (Error Domain=NSCocoaErrorDomain Code=260 "The file “temp” couldn’t be opened because there is no such file." UserInfo=0x7fd6b1c01510 {NSFilePath='Users/chris/project/temp, NSUnderlyingError=0x7fd6b1c01280 "The operation couldn’t be completed. No such file or directory"})

tutoral/project.plist': file does not exist or is not readable or is not a regular file (Error Domain=NSCocoaErrorDomain Code=260 "The file “project.plist” couldn’t be opened because there is no such file." UserInfo=0x7fd6b1d6dd00 {NSFilePath=tutoral/project.plist', NSUnderlyingError=0x7fd6b1d6c6b0 "The operation couldn’t be completed. No such file or directory"})

我也尝试过

在命令字符串中放入撇号

按我建议的几个站点更改数组字符串中的命令

但没有一个成功。

如果我在安排命令时发生任何错误或任何语法错误,请提出建议。提前致谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值