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
#3
(May-03-2021, 07:51 PM)herwin Wrote: In the new code

print(prg)
will give:
Output:
C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe
so the correct value is read into the variable.

No it is not correct. The path should be: "C:\Program Files\Google\Chrome\Application\chrome.exe", so without the double backlashes.
The backslash has a special meaning in Python. So to assign a string literal with backslashes you have to double the backslash to make clear you really mean one backslash.
>>> prg = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
>>> print(prg)
C:\Program Files\Google\Chrome\Application\chrome.exe
So "prg" will contain only single backslashes.
Nowadays a more popular way to assign such a variable is to assign a raw string by putting an "r" before the string literal.
>>> prg = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
>>> print(prg)
C:\Program Files\Google\Chrome\Application\chrome.exe
So make sure you get rid of the double backslashes.
Reply


Messages In This Thread
RE: Subprocess.Popen() not working when reading file path from csv file - by ibreeden - May-04-2021, 08:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Appending sys.path not working with spyder Larz60+ 2 700 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,117 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,225 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,221 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 1,297 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  import a function from another file using relative path paul18fr 6 3,841 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 7,282 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Reading an ASCII text file and parsing data... oradba4u 2 1,590 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  Understanding subprocess.Popen Pedroski55 6 2,349 May-12-2024, 10:46 AM
Last Post: Pedroski55
  File Handling not working properly TheLummen 8 4,209 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