카테고리 없음

java로 exe파일 실행 후 결과값 반환하기

숲별 2023. 12. 11. 17:06
728x90

 

https://bono915.tistory.com/entry/JAVA-%ED%8C%8C%EC%9D%BC-%EC%8B%A4%ED%96%89

 

[JAVA] exe 파일 실행

JAVA에서 파일을 불러오는 것이 아닌 exe파일을 직접 실행하는 소스입니다. 예제를 통해 진행하겠습니다. 아래 소스와 같이 간단하게 exe파일을 실행시킬 수 있고 별도의 library없이 JAVA로 실행이

bono915.tistory.com

 

https://shonm.tistory.com/207

 

[ Java ] 외부 실행파일 (exe 등) 실행

Runtime rt=Runtime.getRuntime(); String exec1="\""+root+"m_imagefusion.exe"+"\""; //m_imageFusion.exe 실행 System.out.println("exec1============>"+exec1); String exec2 = "abc"; //exec2 는 argument, 즉 인자임 String exec=exec1+" "+exec2; //전체 실

shonm.tistory.com

 

 

https://sumni.tistory.com/134

 

[JAVA] 자바 외부 파일/ 외부 프로그램/ 명령어 실행 (exec)

exec() exec() 메소드는 Runtime 클래스의 getRuntime() 메소드를 사용하여 Runtime 객체를 생성한 다음, Runtime 객체의 exec() 메소드를 호출하여 외부 프로그램을 실행합니다. exec() 메소드는 실행할 외부 프

sumni.tistory.com

 

process = rt.exec(String.format("create_exe_v4.exe %s", file));

 

Process process;
if (isWindows) 
{
    process = Runtime.getRuntime()
      .exec(String.format("cmd.exe /c dir %s", homeDirectory));
} 
else 
{
    process = Runtime.getRuntime()
      .exec(String.format("sh -c ls -l %s", homeDirectory));
}

https://yjkim97.tistory.com/70

 

[JAVA] java에서 shell command 실행

2021.11.24 SpringBoot 백엔드 서버에서 데이터베이스에 등록된 command를 실행하고 그 응답을 받아오는 기능을 구현하게 되었다. 본격적으로 구현하기에 앞서 어떻게 실행하고 결과를 받아오는지 한번

yjkim97.tistory.com

 

 java.lang....

Runtime, Process

https://byul91oh.tistory.com/249

 

[Java] Process, ProcessBuilder 자바에서 프로세스 다루기

1. 자바에서의 Process Runtime 클래스는 자바 런타임 환경을 캡슐화 한다. Runtime 클래스는 new 할 수 없지만 Runtime.getRuntime ()이라는 static 메소드를 이용하여 현재 실행중인 프로그램의 Runtime클래스에

byul91oh.tistory.com

	public String runExe() {
		Runtime rt = Runtime.getRuntime();
		
		// 실행할 파일의 경로
		String tmpfile = System.getProperty("user.home");
		System.out.println("=========directory : "+ tmpfile);	
		String file = "C:\\Users\\stlogic\\git\\AI\\AI\\create_exe_v4.exe";
		Process pro;
		StringBuilder result = new StringBuilder();
		
		try {
			System.out.println("=========START : Use Runtime=========");	
			System.out.println("=========directory : "+ file);	
			pro = rt.exec(file);
			pro.waitFor();
			Reader reader = new InputStreamReader(pro.getInputStream());

		    for (int data = reader.read(); data != -1; data = reader.read()) {
		      result.append((char)data);
		    }

		    System.out.println("=========result : " + result.toString());
//			System.out.println(new InputStreamReader(pro.getInputStream()));
//			StreamGobbler streamGobbler = new StreamGobbler(pro.getInputStream(), System.out::println);
//			Executors.newSingleThreadExecutor().submit(streamGobbler);
			System.out.println("=========END : Use Runtime=========");
			
		}catch (IOException e) {
		    e.printStackTrace();
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		return result.toString();
	}
}

 

 

python으로 만들고 shell 통해서 통신

아니면 https://d2.naver.com/helloworld/1113548 와 같이 프로세스로 실행

 

 

 

https://velog.io/@changing/%EC%9E%90%EB%B0%94%EC%97%90%EC%84%9C-%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EC%8B%A4%ED%96%89

 

자바에서 파이썬 실행

ProcessBuilder를 이용해서 같은 패키지안에 있는 파이썬 파일을 실행시킨다.첫 인자는 python.exe의 경로인데 환경변수 설정 때문에 python 명령만 적어줘도 실행 가능 세번쩨 인자는 파이썬 파일에 줄

velog.io

ProcessBuilder를 이용해서 같은 패키지안에 있는 파이썬 파일을 실행시킨다.
첫 인자는 python.exe의 경로인데 환경변수 설정 때문에 python 명령만 적어줘도 실행 가능
세번쩨 인자는 파이썬 파일에 줄 인자