2017-05-08 8 views
1

를 실행, 나는 오류를 얻을파이썬 : 오류 내가 CentOS는에서 다음과 같은 기능을 실행할 때 subprocess.popen

def install_requests_lib(): 
    try: 
     import requests 
     return 
    except ImportError, e: 
     print "module does not exist, installing..." 
     if(platform.system().lower()=='darwin'): 
      print "install requests before proceeding, run **sudo pip install requests**" 
      sys.exit(2) 
     elif(platform.system().lower()=='linux'): 
      print "installing" 
      p=Popen(["yum","-y","install","python-requests"], stdout=PIPE, shell=True) 
      p.communicate() 
      print p.returncode 

오류 : 잘못 왜

module does not exist, installing... 
installing 
You need to give some command 
1 

내가 알아낼 수 없습니다.

나는 stdin=PIPE 인수로 실행했지만 여전히 같은 오류가 발생합니다.

+1

스크립트에'yum install'을 할 수있는 권한이 있습니까? 모든 출력을 보려면 stderr을 stdout으로 재지 정할 수도 있습니다. – grundic

답변

1

shell=True을 지정하면 "yum" 뒤에 arg 목록의 인수가 실행되지 않습니다. shell=True 인수를 제거하면 제대로 작동합니다.

양자 택일로, 당신은 문자열로 전체 명령 줄을 공급하고 shell=True 인수를 유지할 수 :

p=Popen("yum install -y python-requests", stdout=PIPE, shell=True) 

을하지만 일반적으로, for many reasons이 그렇게 낙담입니다.

1

yum install -y을 의미 할 때 yum -y install을 실행하려고합니다.