java - 通过 ProcessBuilder 将字符串传递给批处理文件

标签 java batch-file format

我正在使用 Java ProcessBuilder 将字符串作为参数传递给批处理文件。

ProcessBuilder pb = new ProcessBuilder( "batch.bat", "jason mary molly");

批处理文件...

 @ECHO OFF
 SET V1=%1
 ECHO %V1%
 pause

批处理文件输出是这样的(注意双引号):

“杰森·玛丽·莫莉”

如果我只传入 1 个字符串,则找不到引号!我的问题是,我正在编写一个相当复杂的程序,它要求这 3 个参数不能用引号引起来,否则它们将被程序视为一个文件名而不是 3 个单独的参数。有没有办法删除这些双引号?

最佳答案

尝试:%~1 它应该去掉引号

有关更多信息,请输入:for/? |更多 +121 在 cmd 中。这是引用引用:

%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file
%~$PATH:I   - searches the directories listed in the PATH
               environment variable and expands %I to the
               fully qualified name of the first one found.
               If the environment variable name is not
               defined or the file is not found by the
               search, then this modifier expands to the
               empty string

修饰符可以组合以获得复合结果:

%~dpI       - expands %I to a drive letter and path only
%~nxI       - expands %I to a file name and extension only
%~fsI       - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
               environment variable for %I and expands to the
               drive letter and path of the first one found.
%~ftzaI     - expands %I to a DIR like output line

关于java - 通过 ProcessBuilder 将字符串传递给批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018707/

相关文章:

java - 未知的框架尺寸

java - 反序列化后 transient 字段变为空?

windows - 从 DOS/Windows 批处理文件运行 Sybase SQL 命令

batch-file - 转换后需要删除脚本,ffmpeg

android - 无法在 Windows 10 中安装 sdkmanager

python - 使用win32 python将excel中的一列数据格式化为百分比

java - 使用 ReentrantLock 避免死锁

php - 调整图像大小和图像格式

带 { } 的 python 格式函数

java - 如何将网站的 HTML 转换为图像?