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
  Did subprocess.Popen() causes main routine to pause stdout? liudr 4 258 May-04-2021, 08:58 PM
Last Post: liudr
  code for CSV file to html file without pandas jony057 1 167 Apr-24-2021, 09:41 PM
Last Post: snippsat
  Copy column from one existing excel file to another file mkujawsk 0 216 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 191 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 237 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  Reading a csv file Led_Zeppelin 2 420 Feb-26-2021, 05:48 AM
Last Post: buran
  reading a csv file Led_Zeppelin 3 553 Feb-19-2021, 02:16 PM
Last Post: Led_Zeppelin
  disable subprocess.popen prompt echo paul18fr 1 294 Feb-04-2021, 02:50 AM
Last Post: Larz60+
  Add file to sys.path permanently hcccs 5 502 Jan-31-2021, 11:26 AM
Last Post: hcccs
  Is there anyway to make a .py file into a .exe file? Oshadha 2 334 Jan-13-2021, 04:58 AM
Last Post: Oshadha

Forum Jump:

User Panel Messages

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