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
#6
(May-04-2021, 08:28 AM)ibreeden Wrote:
(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.

Thank you for your response and suggestions.

I have tried with the single and double backslashes in the csv file. The error message stays the same in both cases.

How do I read the values from the csv file into the prg variable as a raw string?
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  File Handling not working properly TheLummen 8 761 Feb-17-2024, 07:47 PM
Last Post: TheLummen
  Absolute paths in subprocess - file not found kittyticker 4 502 Jan-28-2024, 10:37 PM
Last Post: kittyticker
  file open "file not found error" shanoger 8 1,167 Dec-14-2023, 08:03 AM
Last Post: shanoger
Information subprocess.Popen() suddenly giving me grief? davecotter 3 628 Dec-13-2023, 10:49 PM
Last Post: davecotter
  working directory if using windows path-variable chitarup 2 744 Nov-28-2023, 11:36 PM
Last Post: chitarup
Sad problems with reading csv file. MassiJames 3 658 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Use PM4PY and create working file thomaskissas33 0 680 Nov-14-2023, 06:53 AM
Last Post: thomaskissas33
  Reading in of line not working? garynewport 2 863 Sep-19-2023, 02:22 PM
Last Post: snippsat
  Need to replace a string with a file (HTML file) tester_V 1 779 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Reading a file name fron a folder on my desktop Fiona 4 931 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

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