2013-12-08 1 views
0

충분하지 인수를하지만 난 파이썬에 포함 할 때 점점 :파이썬 -이 라인 형식 오류 해결하는 방법이</p> <p>터미널 명령 줄에서의 작업을 형식 문자열

$ amixer -c2 | grep "Simple mixer control 'Mic',0" -A 5 | grep "Mono: " | sed -e 's/Capture /\n/g' | tail -1 | awk '{print $2}' | sed -e 's/%]//g' | sed -e 's/\[//g' 
88 

파이썬 :

tmp = "2" 
a = """amixer -c%s | grep "Simple mixer control 'Mic',0" -A 5 | grep "Mono: " | sed -e 's/Capture /\n/g' | tail -1 | awk '{print $2}' | sed -e 's/%]//g' | sed -e 's/\[//g'""" % tmp 
print "Reply " + a 
a = os.popen(a).read() 
print a 

오류 :

Running: /var/tmp/p/test.py (Sun Dec 8 20:58:07 2013) 


Traceback (most recent call last): 
    File "/var/tmp/p/test.py", line 2, in <module> 
    a = """amixer -c%s | grep "Simple mixer control 'Mic',0" -A 5 | grep "Mono: " | sed -e 's/Capture /\n/g' | tail -1 | awk '{print $2}' | sed -e 's/%]//g' | sed -e 's/\[//g'""" % tmp 
TypeError: not enough arguments for format string 


Execution Successful! 
+1

시도 : a = r ('amixer -c2 | grep "간단한 믹서 컨트롤'Mic ', 0"-A 5 | grep "모노 :"| sed -e'/ 캡처/\ n/g '| 꼬리 -1 | awk '{인쇄 $ 2}'| sed -e 's/%] // g'| sed -e 's/\ [// g' 88 '). 확실하지 않지만 원시 문자열은 트릭을해야합니다! – Vivek

답변

2

당신은 sed 중 하나에 그 일을 참조하십시오 여기에 비트

... | sed -e 's/%]//g' | ... 

변경 :

... | sed -e 's/%%]//g' | ... 

이것은 당신이 python에 문자열에서 %을 탈출하는 방법입니다.

+0

%%에서 패스 한 후, 이제 다음과 같이 나타납니다.'Reply amixer -c2 | grep "간단한 믹서 컨트롤 'Mic', 0"-A 5 | grep "모노 :"| sed -e 's/Capture/ /g'| 꼬리 -1 | awk '{print $ 2}'| sed -e 's/%] // g'| 나오지도 -e '의/\ [// g' 나오지 : -e 표현 # 1, 문자 11 : 종료되지 않은's의 '명령 그렙 : 오류 쓰기 : 브로큰 pipe' – YumYumYum

+0

확인을 - 감사합니다, \\ n은 내가 필요 – YumYumYum