gpt4 book ai didi

java - 使用 cmd.exe 启动 Java 工具

转载 作者:行者123 更新时间:2023-12-02 08:24:38 24 4
gpt4 key购买 nike

我正在尝试从 Java 在其自己的 cmd.exe 窗口中启动 Java 命令行工具。我使用 ProcessBuilder 启动以下操作:

cmd.exe /k "C:\Program Files (x86)\JavaSoft\jre\1.5.0_07\bin\java.exe"

这有效。这也有效:

cmd.exe /k "C:\Program Files (x86)\JavaSoft\jre\1.5.0_07\bin\java.exe" -version

但是当我尝试运行以下命令时

cmd.exe /k "C:\Program Files (x86)\JavaSoft\jre\1.5.0_07\bin\java.exe" "test a"

我收到一条错误消息,指出找不到“C:\Program”。我预计会从 java.exe 中得到异常。我需要能够在某些参数中使用引号。有什么办法可以做到这一点吗?

最佳答案

来自“cmd/?”:

  1. If all of the following conditions are met, then quote characters on the command line are preserved:

    • no /S switch
    • exactly two quote characters
    • no special characters between the two quote characters, where special is one of: &<>()@^|
    • there are one or more whitespace characters between the the two quote characters
    • the string between the two quote characters is the name of an executable file.
  2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character.

好的,这解释了为什么如果有两个以上的引号就不起作用。但这并没有解释到底如何解决问题。值得庆幸的是,谷歌has the answer :

cmd.exe /k ""d:\laj soft\java.exe" "test a""

关于java - 使用 cmd.exe 启动 Java 工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4782129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com