On 05/15/2017 02:48 AM, Steven D'Aprano wrote:
On Sun, May 14, 2017 at 10:57:57PM -0500, Jim wrote:
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.

I think your problem is that you're telling subprocess to run a
command called:

ebook-viewer
/home/jfb/Documents/eBooks/Javascript/GOOGLE_SHEETS/googlespreadsheetprogramming.epub

 with no arguments. What you want is a command called:

ebook-viewer

and a single argument:

/home/jfb/Documents/eBooks/Javascript/GOOGLE_SHEETS/googlespreadsheetprogramming.epub

 I think (but haven't tried it) that the simplest way to fix that is
to change the entry in self.programs from:

self.programs = ['jedit', 'google-chrome', 'doublecmd',
'ebook-viewer
/home/jfb/Documents/eBooks/Javascript/GOOGLE_SHEETS/googlespreadsheetprogramming.epub']


to:

path_to_file =
'/home/jfb/Documents/eBooks/Javascript/GOOGLE_SHEETS/googlespreadsheetprogramming.epub'



self.programs = ['jedit',
'google-chrome', 'doublecmd', ['ebook-viewer', path_to_file], ]

I made the changes you suggested.

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

I noticed you have a , between the last two ]],s. I don't think you meant that but I tried it both ways just incase.


and see if that fixes it. (It may not be enough, or the right
approach, but at least you'll get a different error if it is wrong
:-)

Unfortunately you are correct, I did get a different error message.

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 1474, in _execute_child
    executable = os.fsencode(executable)
  File "/usr/lib/python3.5/os.py", line 862, in fsencode
raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
TypeError: expect bytes or str, not list

Traceback (most recent call last):
File "/home/jfb/MyProgs/Scripts/place_windows_OO_WS3.py", line 78, in <module>
    Place()
File "/home/jfb/MyProgs/Scripts/place_windows_OO_WS3.py", line 21, in __init__
    self.open_and_move()
File "/home/jfb/MyProgs/Scripts/place_windows_OO_WS3.py", line 31, in open_and_move p = Popen(['xdotool', 'search', '--classname', self.classname[self.program]], stdout=subprocess.PIPE)
TypeError: unhashable type: 'list'

Regards,  Jim


The difference is that the shell automatically splits things on
spaces, so it sees the space between ebook-viewer and the long path,
and treats the first word as the executable and the second as an
argument. But Python treats the whole string, spaces and quotes
included, as the executable.




_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to