[英]Is there anyway to give cmd prompt command in java
I'm trying to run cmd prompt command using java, i have a source path and destination path and i'm flippig the image.我正在尝试使用 java 运行 cmd prompt 命令,我有一个源路径和目标路径,我正在翻转图像。 Flipped image should get copied to destination.
翻转的图像应该被复制到目的地。 The image is getting copied but not the flipped image.
图像正在被复制,但不是翻转的图像。 I'll share my code below, kindly let me know if anything else is needed.
我将在下面分享我的代码,如果需要其他任何东西,请告诉我。
@Test
public void executeCommandJpgDifferentPaths() throws IOException{
Path resourceDirectory = Paths.get("src\\main\\resources\\download.jpg");
Path destination = Paths.get(demoFolder.getAbsolutePath(),"download_output.jpg");
String command = "magick convert -flip resourceDirectory destination " ;
Boolean output = flipImplementation.executeCommand(command);
Files.copy(resourceDirectory,destination);
Assert.assertTrue(output);
try {
Thread.sleep(123456789L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
I have tried this using, 'destinationDirectory.resolve'.We need to use as below :我已经尝试过使用'destinationDirectory.resolve'。我们需要使用如下:
@Test
public void executeCommandJpgDifferentPaths() throws IOException{
Path resourceDirectory = Paths.get("src\\main\\resources");
Path resourcePath = resourceDirectory.resolve("download.jpg");
Path destinationDirectory = Paths.get(demoFolder.getAbsolutePath());
Path destinationPath = destinationDirectory.resolve("download_output.jpg");
String command = "magick convert -flip " + resourcePath + " " + destinationPath ;
Boolean output = flipImplementation.executeCommand(command);
Assert.assertTrue(output);
try {
Thread.sleep(123456789L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
You are using a plain string.您正在使用普通字符串。 But you should be using variables inside.
但是你应该在里面使用变量。
Replace代替
String command = "magick convert -flip resourceDirectory destination " ;
with和
String command = "magick convert -flip " + resourceDirectory.getAbsolutePath() + " " + destination.getAbsolutePath();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.