2016-04-05 45 views
-4

私はtxtファイルから別のものを読み込むためにこの関数を使用しています。これまでのところ、ファイルエクスプローラのWebページやファイルの場所で動作します。ただし、txtファイルで場所が渡されると、ファイルは.exeには実行されません。外部の.exeファイルを実行するPython 3

これは私がelse文で苦労しています

def Run(): 
    while True: 
     try: 
      fr = open('AutoLoader.txt', 'r') 
      lines = fr.readlines() 

      for line in lines: 
       if line[0:3] == 'web': 
        #open in the browser 
        os.startfile(line[3:]) 
       elif line[0:3] == 'loc': 
        cmd = line[3:] 
        print(cmd) 
        subprocess.Popen('explorer "' + cmd + '"') 
       else: 
        #open the program 
        run = ('r"' + line + '"') 
        process = subprocess.Popen(run, stdout=subprocess.PIPE) 
      fr.close() 
      break 
     except FileNotFoundError: 
      print("Program not setup") 
      print("running setup") 
      Setup() 

を使用してい機能です。それは動かないものです。

あなたは

+1

このコマンドを見るには 'print(run)'を試してください(おそらくここに投稿してください)、 'program = subprocess.Popen([run]、stdout = subprocess.PIPE)'と ' – jDo

+1

[あなたの関数名についてはどうしたらよいですか?](https://www.python.org/dev)を読むことをお勧めします。/peps/pep-0008 /#function-and-method-arguments):) – Signal

+1

'' r '' 'から' r'を取り出します。あなたがそこに置かれたとは思っておらず、 .exeファイルの実行 – martineau

答えて

0

あなたは.exeファイルを実行するためにsubprocess.call( "path_to_exe"、args_for_exe)を使用することができますありがとうございました。

関連する問題