저는 서브 프로세스를 시작하고 서브 프로세스 stdin에 쓰는 파이썬 스크립트를 작성하려고합니다. 출력에 대한 일부 테스트를 수행하고 stdin에 더 많은 명령을 씁니다.stdin에 쓰기, 액세스가 거부되었습니다.
나는 시도했다 :
def get_band():
print "band"
p = subprocess.Popen(["/path/to/program","-c","-"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
ran_stdout = p.communicate(input='show status')[0]
print(ran_stdout)
인쇄 문을 준다 그러나 :
Unable to connect at 127.0.0.1, Connection refused.
내가이 권리를하고있는 중이 야 경우 궁금 해서요? 다음은 실행하려는 프로세스에 대한 설명서입니다. 마지막 옵션을 사용하고 싶습니다.
Running the tool from the Linux shell allows additional options, depending on the options given to the command. The options are as follows:
-h Displays help about the command
-c <Filename> Instead of taking typed commands interactively from a user the commands are read from the named file, i.e. in batch mode. When all commands are processed the CLI session ends automatically.
-c - As above but reads command from Linux stdin. This allows commands to be ‘piped’ to the program.
메시지가 하위 프로세스에서 생성 될 수 있습니까? – Bogdacutu
네, 고맙습니다. 왜 그런지, 허가를 얻는 방법이 궁금합니다. 이러한 매개 변수를 사용하여 터미널에서 프로세스를 실행하면 정상적으로 실행됩니다. – Paul