英文:
Is there anyway to give cmd prompt command in java
问题
@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'm trying to run cmd prompt command using java, i have a source path and destination path and i'm flippig the image. 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();
}
}
答案1
得分: 1
我已尝试使用'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();
}
}
英文:
I have tried this using, 'destinationDirectory.resolve'.We need to use as below :
@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();
}
}
答案2
得分: 0
你正在使用普通字符串。但是你应该在内部使用变量。
将
String command = "magick convert -flip resourceDirectory destination" ;
替换为
String command = "magick convert -flip " + resourceDirectory.getAbsolutePath() + " " + destination.getAbsolutePath();
英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论