Python에서 Command 명령어 실행하는 예제
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
31
32
33
34
35
36
37
38
import os
import subprocess
 
def ExecuteCmd(self, strCmd):
    print "[ExecuteCmd] %s" % (strCmd)
    pipe = subprocess.Popen(strCmd,
        shell=True,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
 
    pipe.stdin.close()
 
    retOutputList = []
 
    while True:
        pipe.poll()
        out = pipe.stdout.readline()
        if (out):
           retOutputList.append(out)
           if( bLoggingOutput ):
               self.Log(out)
        retCode = pipe.returncode
        if (out == "" and retCode != None):
           break;
 
    return (retCode, retOutputList)
     
def main():
    (retCode, stdout) = ExecuteCmd('svn --version')
    print 'retCode : ' + str(retCode)
    print stdout
         
if __name__ == "__main__":
    try:
        main()
    except os.error, err:
        print str(err)
2012/01/19 11:41 2012/01/19 11:41

글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다

덧글을 달아 주세요