简体   繁体   English

无论如何在java中给出cmd提示命令

[英]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.

相关问题 打开cmd提示符并执行命令java - opening cmd prompt and execute command java 以管理员身份从java启动命令提示符(CMD) - Start Command Prompt (CMD) from java as Administrator 如何在java中等待并关闭命令提示符 - how to give wait & close the command prompt in java 输入命令并获取命令提示符完整输出到Java中的textarea - Give input command and Get Command Prompt complete Output to textarea In Java 作为命令,它可以从cmd提示符下正常运行,但不能从Java代码中运行 - As a command it runs fine from cmd prompt but not from java code Java命令提示符中无法识别的cmd Windows路径和环境变量 - cmd windows path and environment variables unrecognized in Java Command Prompt Java Selenium在没有IDE的情况下通过命令提示符CMD Windows运行 - Java Selenium Run through Command Prompt CMD Windows Without IDE 从Java代码打开命令提示符并运行一些命令并阅读cmd提示符显示? - open a command prompt from java code and run some commands and read the cmd prompt display? 如何使用java cmd在Windows命令提示符下的Eclipse中运行.java文件? - How to run a .java file created in Eclipse on windows command prompt with java cmd? PHP Exec和命令提示符(cmd)中的不同编码 - Different Encoding in PHP Exec and in command prompt (cmd)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM