셸 Ghostscript 명령으로 문자열 리디렉션과 파이썬에 문제가 있습니다.파이썬 - 서브 프로세스 모듈 -Ghostscript- 2> & 1
이 NP이 실행 :
subprocess.call(["gs", "-q","-dBATCH", "-dNOPAUSE","-sDEVICE=bbox", "input.pdf"])
을하지만 추가 오류 2> & 1 얻을 :
subprocess.call(["gs", "-q","-dBATCH", "-dNOPAUSE","-sDEVICE=bbox", "input.pdf","2>&1"])
또는 : 나는 2를 사용하려면
subprocess.call(["gs", "-q","-dBATCH", "-dNOPAUSE","-sDEVICE=bbox", "input.pdf","2>&1",">/dev/null"])
을> & 1을 입력하여 'grep'을 적용하십시오. 오류의
샘플 :
Error: /undefinedfilename in (2>&1) Operand stack:
Execution stack: %interp_exit .runexec2 --nostringval--
--nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:1156/1684(ro)(G)--
--dict:1/20(G)-- --dict:77/200(L)-- Current allocation mode is local Last OS error: 2 GPL Ghostscript 9.05: Unrecoverable error, exit code 1 1
하는 것은 여전히 같은 명령을 실행하는 방법에 해결되지는 : 당신이 목록으로 인수를 전달하고 있기 때문에
subprocess.call("gs -q -dBATCH -dNOPAUSE -sDEVICE=bbox input.pdf 2>&1
| egrep -v HiResBoundingBox | egrep -o "[0-9]{1,}",shell=True)
은 "미해결"명령 (더 나은이
shell=True
와 보안 문제를 비켜 때문에) ... '더 나은'나 -은 당신이 원하는 것을 할 것입니다 실행하려면 작동하지 않습니다? 아니면'shell = False'로하려고하면 작동하지 않습니까? (그것은'shell = True'로 동작해야합니다.) – mgilson
초기 버전에는 오타가있었습니다. 2 개의 && 1은 2 개의 다른 위치에 있었을 것입니다. 이 오류의 원인인지 확인하십시오. 그렇지 않으면, 파이썬 (내가 잘 알고 있지는 않지만)이 종류의 리디렉션을 지원하지 않거나 다른 구문을 요구할 수 있습니다. –
Ghostscript의 * 'Interacting with Pipes'*에 대한 정보 : http://git.ghostscript.com/?p=ghostpdl.git;a=blob_plain;f=gs/doc/Use.htm;hb=HEAD#Pipes - 해결 방법을 찾는 데 도움이 될 수 있습니다. –