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
#11
Thanks !

Most now works using the code you mention, but not all.

the csv file has these lines:

C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe
C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe
C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\FoxitUpdater.exe
C:\\Users\\zorin\\Documents\\Python Scripts\\test folder\\JavaUpdate.bat
C:\\Users\\zorin\\Documents\\Python Scripts\\test folder\\KeepassXC Update.bat
C:\\Program Files\\Tracker Software\\Update\\TrackerUpdate.exe
C:\\Program Files (x86)\\2BrightSparks\\SyncBackFree\\SyncBackFree.exe
C:\\Program Files\\VideoLAN\\VLC\\vlc.exe
C:\\Users\\zorin\\Documents\\Python Scripts\\test folder\\windowsupdate.bat
C:\\Users\\zorin\\AppData\\Roaming\\Zoom\\bin\\Zoom.exe

The code works fine for all lines, except 2:

SyncbackFree (7)
vlc.exe (8)

if I chose either of these from my menu I get this error message:

Error:
Traceback (most recent call last): File "test_csv.py", line 33, in <module> mainmenu() File "test_csv.py", line 31, in mainmenu subprocess.Popen([prg]) File "C:\Users\zorin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 858, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\zorin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1311, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified
I copied the line from the csv into a command prompt and the programs open fine, so I know the paths and file names are correct.

Any suggestions why these two give an error message and it works for the rest?
Reply
#12
Ask Python to print(repr(prg)) before it attempts to execute each program with subprocess.Popen()
Reply
#13
I still believe something is going wrong with the interpretation of special characters. For example: you can insert a "vertical tab" by asigning the literal: "\v".
See this:
>>> print("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe")
C:\Program Files\VideoLAN\VLC\vlc.exe
>>> print("C:\Program Files\VideoLAN\VLC\vlc.exe")
C:\Program Files\VideoLAN\VLC
                             lc.exe

>>> print("C:\\Program Files (x86)\\2BrightSparks\\SyncBackFree\\SyncBackFree.exe")
C:\Program Files (x86)\2BrightSparks\SyncBackFree\SyncBackFree.exe
>>> print("C:\Program Files (x86)\2BrightSparks\SyncBackFree\SyncBackFree.exe")
C:\Program Files (x86)BrightSparks\SyncBackFree\SyncBackFree.exe
In the first example ("C:\Program Files\VideoLAN\VLC\vlc.exe") you see the "\v" is replaced by a "vertical tab".
In the second example ("C:\Program Files (x86)\2BrightSparks\SyncBackFree\SyncBackFree.exe") you can see the "\2" is replaced by ... I don't know. It disappeared. Apparently it is seen as an octal code.

See String literals to see how backslashes are handled.
Could it be something like this is happening when assigning literals to strings?

I believe it is allowed in Python for Windows to use the forward slash instead of the backslash in folder paths. Perhaps you can try that.
Reply
#14
Thanks for all your help.

When printing the path before the subprocess.popen I noticed that in the file paths for the two programs where it did not work the space between 'Program' and 'Files' was replaced with '\xa0'

When I manually retyped the files paths in the csv file that was fixed and now it works fine.

Thanks again
Reply


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