首页 > 解决方案 > Exiftool 没有打印到 ProcessBuilder 中的文件?

问题描述

我正在使用 aProcessBuilder将输出打印exiftool到文件中。我正在尝试在 .opus 文件上运行此命令:exiftool Aero.opus > Aero.txt. 这在终端中运行得很好,但在 processbuilder 中似乎无法解析它。

这是一个简单的程序。请注意,该目录设置为/home/sarah并且该Aero.opus文件存在于该目录中。

另请注意,输出打印到控制台而不是像预期的那样打印到文件,并且它说它无法识别 > 运算符。

@Test
public void testExifprocess() throws IOException {
    //File Located at /home/sarah/Aero.opus
    ProcessBuilder builder = new ProcessBuilder("exiftool", "Aero.opus", ">", "Aero.txt").directory(Paths.get("/home/sarah").toFile())
            .inheritIO();
    builder.start();
}

这是输出:

Running com.protonmail.sarahszabo.stellaropusconverter.tests.StellarDiskManagerTest
File not found: >
File not found: Aero.txt
======== Aero.opus
ExifTool Version Number         : 10.80
File Name                       : Aero.opus
Directory                       : .
File Size                       : 13 MB
File Modification Date/Time     : 2018:06:29 19:19:08-04:00
File Access Date/Time           : 2018:07:16 23:20:27-04:00
File Inode Change Date/Time     : 2018:07:16 23:20:27-04:00
File Permissions                : rw-rw-r--
File Type                       : OPUS
File Type Extension             : opus
MIME Type                       : audio/ogg
Opus Version                    : 1
Audio Channels                  : 2
Sample Rate                     : 48000
Output Gain                     : 1
Vendor                          : Lavf58.17.100
Title                           : Aero
Artist                          : Daniel Deluxe
Picture Type                    : Front Cover
Picture MIME Type               : image/png
Picture Description             : Daniel Deluxe -- Aero.png
Picture Width                   : 1280
Picture Height                  : 720
Picture Bits Per Pixel          : 0
Picture Indexed Colors          : 0
Picture Length                  : 946992
Picture                         : (Binary data 946992 bytes, use -b     option to extract)
    1 image files read
    2 files could not be read

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

主文件夹: 主文件夹

我的操作系统是 Kubuntu 18.04,带有 Java 8_171。

标签: javaubuntuprocessjava-8exiftool

解决方案


我假设它只是将“>”作为参数传递给 exiftool。我建议你使用 https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#redirectOutput(java.io.File)

ProcessBuilder proc= new ProcessBuilder().command("exiftool", "Aero.opus");
proc.redirectErrorStream(true);
proc.redirectOutput(new File("Aero.txt"));
proc.start();

推荐阅读