java调用scrapy无反应 String writeFilePath="";
String path="A:\\0_document\\pythonWorkSpace\\ysu\\ysu";
// String path="crawl ";
//python脚本的路径
String executePath = path + "\\main.py";
// String executePath = path + "ysu_spider";
//执行命令Arr
System.out.println(executePath);
// System.out.println(System.getProperty("user.dir"));
String[] cmdArr = new String[]{"python",executePath};
// String[] cmdArr = new String[]{"scrapy",executePath};
//参数分别为: 执行命令;执行此脚本的路径
Process process = null;
try {
System.out.println("1");
process = Runtime.getRuntime().exec(cmdArr,null,new File(path));
System.out.println(process);
InputStream inputStream = process.getInputStream();
System.out.println(inputStream);
byte[] b = new byte[1024];
while (inputStream.read(b) != -1) {
writeFilePath = new String(b);
System.out.println(writeFilePath);
}
// 返回linux执行状态码,0为执行正常
int statusNum = process.waitFor();
System.out.println(statusNum);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
// }
} catch (InterruptedException e) {
e.printStackTrace();
}控制台:A:\0_document\pythonWorkSpace\ysu\ysu\main.py
1
java.lang.ProcessImpl@681a9515
java.io.BufferedInputStream@3af49f1cmain.pyfrom scrapy import cmdline
import os
if __name__ == '__main__':
os.chdir("A:/0_document/pythonWorkSpace/ysu/ysu");
print(1+2)
cmdline.execute('scrapy crawl ysu_spider'.split())到底怎么回事呀?救救孩子!
添加回答
举报
0/150
提交
取消