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

Steven D'Aprano steve at pearwood.info
Mon May 15 03:48:50 EDT 2017

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 

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

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


and a single argument:

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']


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

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 :-)

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 


More information about the Tutor mailing list