
JAVA 调用cmd命令 从而调用Python命令
CMD的命令
cmd /c cd /f F:JSCuteRCuteR-masterCuteR-master && CuteR -c 10 -e H -o sample_output.png -v 10 sample_input.png http://www.chinuno.com
本质是通过传参数实现调用python命令来实现效果
package edu.sdut.CMD;
import java.io.IOException;
public class CallCmd {
public static void Cmd(String InputPath , String OutPath ,String content) throws IOException {
Runtime.getRuntime().exec("cmd /c cd F:\JS\CuteR\CuteR-master\CuteR-master && CuteR -c 10 -e H -o "+OutPath+" -v 10 "+InputPath+" "+content);
}
public static void main(String[] args) throws IOException {
// Cmd(null,null);
}
}
下面的写法可通过控制线程来判断是否完成任务,达到同步执行线程的效果
package edu.sdut.CMD;
import java.io.IOException;
public class CallCmd {
public static Integer Cmd(String InputPath , String OutPath ,String content) throws IOException, InterruptedException {
// Process可以控制该子进程的执行或获取该子进程的信息
Process process;
process = Runtime.getRuntime().exec("cmd /c cd F:\JS\CuteR\CuteR-master\CuteR-master && CuteR -c 10 -e H -o "+OutPath+" -v 10 "+InputPath+" "+content);
int i = process.waitFor();
return i;
}
public static void main(String[] args) throws IOException, InterruptedException {
// Cmd(null,null);
Integer cmd = Cmd("", "", "");
System.out.println(cmd);
}
}
效果如下:
挺满意的,完善