2017-11-07 1 views
1

Linux 터미널 창을 열고 Python 파일을 실행하는 프로그램을 작성하려고합니다. 나는 다음과 같은 오류가Python 3에서 gnome-terminal 하위 프로세스를 호출 할 때 "하위 프로세스 (해당 파일이나 디렉토리가 없습니다)를 실행하지 못했습니다"

import subprocess 
subprocess.call(['gnome-terminal', '-x', 'python3 '+filename]) 

: :이 같은 서브 프로세스 모듈과 gnome-terminal 서브 프로세스를 호출 할 때

Failed to execute child process "python3 /home/user/Documents/test.py” (No such file or directory) 

내가 디렉토리에 CD를 시도 /home/user/Documents/test.py 먼저 다음 실행 파일,하지만 작동하지 않았다.

답변

0
을 먼저 파이썬 파일을 실행하려고하고 작동하는지 여부를 작동하는 경우

from subprocess import Popen 

command="gnome-terminal -x python3"+filename 

proc=Popen(command) 

(내가 그 python3가 PATH에 설정되어있는 가정)이 시도 이 시도

:

os.system("gnome-terminal -e 'bash -c \"python3 %s\"'"%filename) 

당신은 또한에 의해 sleep 같은 다른 매개 변수를 추가 할 수 있습니다 세미콜론으로 구분 :

os.system("gnome-terminal -e 'bash -c \"python3 %s; sleep 5\"'") 
0

이되지 다음

python filename 
관련 문제