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
  How to run a particular file in subprocess Shiri 5 277 Nov-24-2021, 09:29 AM
Last Post: ghoul
  Create a 2-channel numpy file from two cvs file containing a 9x9 matrix silvialecc 1 310 Oct-26-2021, 07:59 AM
Last Post: Gribouillis
  Convert legacy print file to XLSX file davidm 1 326 Oct-17-2021, 05:08 AM
Last Post: davidm
Question In need of insight regarding Python file reading mechanisms. EnfantNicolas 7 691 Sep-18-2021, 10:39 AM
Last Post: ndc85430
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 433 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Help with reading json file hhchenfx 5 1,255 Jul-07-2021, 01:58 PM
Last Post: hhchenfx
  [Solved] Reading every nth line into a column from txt file Laplace12 7 1,228 Jun-29-2021, 09:17 AM
Last Post: Laplace12
  help with project of reading and searching big log file korenron 6 591 Jun-24-2021, 01:57 PM
Last Post: korenron
  Create ZIP file not working using ZipFile? korenron 1 612 Jun-13-2021, 04:15 PM
Last Post: korenron
  Read file, reformat and write new file bryanmartin113 1 770 Jun-08-2021, 09:27 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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