[Tutor] No file or directory error using subprocess and Popen

Jim jf_byrnes at comcast.net
Sun May 14 23:57:57 EDT 2017


I am running this on Mint 18.
This is the third script I have written to open and position windows in 
workspaces. The first two work, but trying to open ebook-viewe r 
(calibre) with a specific book produces the following error.
If I run the same command in the terminal it works without an error.


Exception in thread Thread-4:
Traceback (most recent call last):
   File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
     self.run()
   File "/usr/lib/python3.5/threading.py", line 862, in run
     self._target(*self._args, **self._kwargs)
   File "/home/jfb/MyProgs/Scripts/place_windows_OO_WS3.py", line 24, in 
open_it
     subprocess.call([self.program])
   File "/usr/lib/python3.5/subprocess.py", line 557, in call
     with Popen(*popenargs, **kwargs) as p:
   File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
     restore_signals, start_new_session)
   File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
     raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ebook-viewer 
/home/jfb/Documents/eBooks/Javascript/GOOGLE_SHEETS/googlespreadsheetprogramming.epub'

Code:

# place_windows_OO_WS3.py

import subprocess
from subprocess import Popen,PIPE
import threading
import time

class Place():

     def __init__(self):
         self.programs = ['jedit', 'google-chrome', 'doublecmd',
         'ebook-viewer 
/home/jfb/Documents/eBooks/Javascript/GOOGLE_SHEETS/googlespreadsheetprogramming.epub']
         self.classname = {'jedit' : 'sun-awt-X11-XFramePeer',
                             'google-chrome':'google-chrome',
                             'doublecmd':'doublecmd',
                             'calibre-ebook-viewer': 'libprs500'}
         self.open_and_move()

     def open_it(self):
         subprocess.call([self.program])

     def open_and_move(self):
         for self.program in self.programs:
             opener = threading.Thread(target=self.open_it)
             opener.start()
             time.sleep(2)
             p = Popen(['xdotool', 'search', '--classname', 
self.classname[self.program]], stdout=subprocess.PIPE)

             if self.classname[self.program] == 'sun-awt-X11-XFramePeer':
                 wid = str(p.stdout.read())
                 wid = wid[len(wid) - 11 : len(wid) - 3]
                 x = '0'
                 y = '0'
                 print('***jedit***')
             elif self.classname[self.program] == 'google-chrome':
                 wid = str(p.stdout.read())
                 wid = wid[len(wid) - 11 : len(wid) - 3]
                 x = '1924'
                 y = '0'
                 print('***google***')
             elif self.classname[self.program] == 'doublecmd':
                 wid = str(p.stdout.read())
                 wid = wid[len(wid) - 11 : len(wid) - 3]
                 x = '1924'
                 y = '537'
                 print('***double***')
             else:
                 wid = str(p.stdout.read())
                 wid = wid[len(wid) - 11 : len(wid) - 3]
                 x = '2540' #'1924'
                 y = '537'
                 print('***calibre***')
             subprocess.call(['xdotool', 'windowmove', str(wid), x, y])

I did some googling and it seems that subprocess does not have a length 
limit in linux. Could someone tell me how to correct the above error.

Thanks,  Jim



More information about the Tutor mailing list