프로그래밍/LUA
[LUA] 외부 application의 출력 내용(printf등)을 얻어오기 io.popen
고독한 프로그래머
2014. 1. 8. 10:12
1. 테스트를 위한 간단한 응용 프로그램 소스. (Console application)
> 윈도우에서 VC++로 작성했으나, 리눅스 프로그램도 적용 가능합니다.
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
printf("hello lua!!\n");
return 0;
}
>> 출력 결과
hello lua!!
2. lua 코드 (빨간색 부분이 실행할 파일의 경로)
local f = io.popen("D:\\test1.exe", "r")
if f then
local data = f:read("*all")
f:close();
print ("result >> " .. data);
end
>> 출력 결과
result >> hello lua!!
>Exit code: 0
※ 퍼가실땐 출처를 밝혀주세요. (http://shkam.tistory.com/)