Python Forum
Subprocess.Popen() not working when reading file path from csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocess.Popen() not working when reading file path from csv file
#10
(May-04-2021, 03:30 PM)herwin Wrote: The problem appears to be the blank space in the middle of the string (between 'program' and 'files' in the file path)
Should not be a problem,a quick test.
So this run fine no error,and open programs.
import subprocess

core = r'C:\Program Files\Core Temp\Core Temp.exe'
prg = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
print(repr(core))
print(repr(prg))
subprocess.Popen([core])
subprocess.Popen([prg])
Output:
E:\div_code\new λ python p_open.py 'C:\\Program Files\\Core Temp\\Core Temp.exe' 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
If put paths is a file,run fine.
Output:
# prog.csv C:\Program Files\Core Temp\Core Temp.exe,C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
import subprocess
import csv

with open('prog.csv') as f:
    reader = csv.reader(f, delimiter=',')
    prog_lst = list(reader)

for prog in prog_lst[0]:
    subprocess.Popen([prog])
so prog_lst looks like this,se that there are two \\ when read from a file,
then there is no need for r(raw string) as if write/copy path yourself.
>>> prog_lst
[['C:\\Program Files\\Core Temp\\Core Temp.exe',
  'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe']]
Reply


Messages In This Thread
RE: Subprocess.Popen() not working when reading file path from csv file - by snippsat - May-04-2021, 10:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Appending sys.path not working with spyder Larz60+ 2 720 Apr-11-2025, 08:50 AM
Last Post: Larz60+
  How to write variable in a python file then import it in another python file? tatahuft 4 1,140 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 1,237 Nov-21-2024, 11:48 PM
Last Post: haihal
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,231 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 1,316 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  import a function from another file using relative path paul18fr 6 3,876 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 7,340 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Reading an ASCII text file and parsing data... oradba4u 2 1,603 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  Understanding subprocess.Popen Pedroski55 6 2,370 May-12-2024, 10:46 AM
Last Post: Pedroski55
  File Handling not working properly TheLummen 8 4,231 Feb-17-2024, 07:47 PM
Last Post: TheLummen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020