-
[ANT] exec, sshexec로 결과(return, property) 가져오기Software Test/자동화 2016. 1. 26. 17:43반응형
ANT를 좀 더 다양하게 이용하다보면 실행한 결과값을 이용해야할 경우가 있다
이 떄 exec나 sshexec 모두 outputproperty를 이용하면 exec 수행에 따른 결과를 받아올 수 있다.
또한 명령어를 통한 결과값을 받아올 때 줄바꿈까지 오는 경우가 많다.
이 경우에는 line.separotor를 분리해주어야한다.
1. exec<target name="exec_test">
<exec executable="/bin/sh" outputproperty="result">
<arg value="-c" />
<arg value=" ls -al test.xml " />
</exec>
<echo>result : ${result} </echo>
</target>
실행 : ant -f test.xml exec_test
결과
exec_test:
[echo] result : -rw-rw-r-- 1 test test 308 1¿u 26 17:17 test.xml2. sshexec
<target name="sshexec_test">
<sshexec host="localhost"
username="test"
password="test"
command="cat /home/test/test.xml | wc -l"
trust="true"
outputproperty="ssh_result" />
<echo>ssh_result : ${ssh_result} </echo>
</target>
실행 : ant -f test.xml sshexec_test
결과
sshexec_test:
[sshexec] Connection to localhost:22
[sshexec] cmd : cat /home/test/test.xml | wc -l
[sshexec] 10
[echo] ssh_result : 10
[echo]3. 줄바꿈 처리
ssh_result의 경우에는 echo 결과가 다음줄이 나와있고 ssh_result2의 경우에는 echo 결과가 한줄로 나와있다.<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="sshexec_test">
<sshexec host="localhost"
username="test"
password="test"
command="cat /home/test/test.xml | wc -l"
trust="true"
outputproperty="ssh_result" />
<echo>ssh_result : ${ssh_result} </echo>
<for list="${ssh_result}" param="cur" delimiter="${line.separator}" >
<sequential>
<var name="ssh_result2" value="@{cur}" />
</sequential>
</for>
<echo>ssh_result2 : ${ssh_result2} </echo>
</target>
실행 : ant -f test.xml sshexec_test
결과
sshexec_test:
[sshexec] Connection to localhost:22
[sshexec] cmd : cat /home/test/test.xml | wc -l
[sshexec] 10
[echo] ssh_result : 10
[echo]
[echo] ssh_result2 : 10
BUILD SUCCESSFUL반응형'Software Test > 자동화' 카테고리의 다른 글
[GoogleTest] linux에 googletest를 동적라이브러리로 설치 (0) 2017.12.27 [ANT] condition 을 통한 조건문 (0) 2017.11.30 [ANT] user의 home path (0) 2017.11.16 [ANT] SSH / SFTP 사용방법 (0) 2015.12.09 [ANT] Linux에 ANT 설치 (0) 2015.12.09