栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Python

JAVA 调用cmd命令 从而调用Python命令

Python 更新时间:发布时间: 百科书网 趣学号

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);
    }
}

效果如下:

挺满意的,完善

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/280537.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号