python subprocess 调jar包

这个不是很常用,但是有些接口提供java sdk会用到,所以记录一下:
java 打jar不说了,注意命令行java版本和idea一致

package wq;
import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
public class test {
    public static void main(String[] args){
        ArrayList name = new ArrayList<String>();
        name.add("adf");
        System.out.print("Hello,World!");
        String jsonString = JSON.toJSONString(name);
        System.out.println(jsonString);
    }
}
    cmd = ["java", "-jar", "D://project/zjxg-server/loader/a.jar"]
    a = subprocess.run(cmd, capture_output=True, encoding="utf-8")
    b=a.stdout.replace('Hello,World!','')
    import json
    c=json.loads(b)
    print (c,type(c))
    >>>['adf'] <class 'list'>

你可能感兴趣的:(python,python,java,jar,java,intellij-idea)