반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- chartjs
- Python
- COALESCE
- Flux
- chart.js
- PostgreSQL
- node
- or some instances in your deployment group are experiencing problems.
- Spring Error
- docker
- aws
- JavaScript
- Kafka
- codedeploy
- VPN
- kubeflow
- aws cicd
- codepipeline
- IntelliJ
- 도커
- codebuild
- Jenkins
- Airflow
- bootstrap
- codedeploy error
- redis
- AWS CI/CD 구축하기
- java bigdecimal
- SQL
- Spring
Archives
- Today
- Total
Small Asteroid Blog
자바에서 파이썬 파일 실행하기 - processbuilder 본문
728x90
자바에서 외부에 있는 파이썬 파일을 실행시키고자 한다.
자바에서 processbuilder를 사용한다.
자바 프로젝트 내부에서 파이썬 모듈을 설치해주어야 한다.
@RequestMapping(value="pythonbuilder")
@ResponseBody
public String pythonProcessbuilder() throws IOException, InterruptedException {
System.out.println("pythonbuilder ");
String arg1;
ProcessBuilder builder;
BufferedReader br;
arg1 = "D:/Users/Pycharm/Intellijpy/kor_v01.py";
builder = new ProcessBuilder("python",arg1); //python3 error
builder.redirectErrorStream(true);
Process process = builder.start();
// 자식 프로세스가 종료될 때까지 기다림
int exitval = process.waitFor();
//// 서브 프로세스가 출력하는 내용을 받기 위해
br = new BufferedReader(new InputStreamReader(process.getInputStream(),"UTF-8"));
String line;
while ((line = br.readLine()) != null) {
System.out.println(">>> " + line); // 표준출력에 쓴다
}
if(exitval !=0){
//비정상종료
System.out.println("비정상종료");
}
return "pythonconnet";
}
728x90
반응형
'백엔드 > Spring' 카테고리의 다른 글
[spring] Jsoup HTTP error fetching URL. Status=405 (0) | 2021.12.10 |
---|---|
StringBuilder & System.out.println() (0) | 2021.11.24 |
[Java] 구글 뉴스 날짜별로 크롤링하기 (0) | 2021.11.08 |
element is not attached to the page document (0) | 2021.11.04 |
[jquery] select 선택에 따라 두번째 select 변경하기 (0) | 2021.10.29 |