Jrnl: `shlex.split` breaks on Windows paths

Created on 4 May 2015  路  4Comments  路  Source: jrnl-org/jrnl

322 replaced this line

subprocess.call(config['editor'].split() + [tmpfile])

with

subprocess.call(shlex.split(config['editor']) + [tmpfile])

However, shlex is only designed to work on POSIX systems on so breaks on Windows. On Windows, if you specify an editor using 'normal' Windows paths (i.e. using backslashes, like 'C:\Program Files (x86)\Notepad++\notepad++.exe`), it gives the un-helpful error:

FileNotFoundError:[WinError 2] The system cannot find the file specified

To the (Windows) user, this is strange because paths to journal files can be given 'as normal' (i.e. with backslashes) without issues.

Four possible solutions come to mind:

  1. revert #322
  2. use shlex on POSIX systems and not on non-POSIX systems
  3. use double backslashes or (single) forward slashes in the configuration
  4. find a replacement for shlex that works on both POSIX systems (e.g. Mac) and Windows

I don't like 1, because although it is simplest for me personally, I know it was meant to fix a problem for others.

I don't particularly like 2, because it increases the complexity of the code and makes it nearly impossible for one person to test both code branches (that inability to test is what brought us here).

3 is workable, but is non-intuitive at best.

My preferred options would be 4, but I only know how to do the first three at the moment.

@pcarranza @philipsd6 @maebert Suggestions?

Most helpful comment

Oh Windows, developing without you would be like vanilla ice cream without ketchup.

@MinchinWeb Can you test whether this works if we call silex with posix=False? Or rather,

subprocess.call(shlex.split(config['editor'], posix="win" not in sys.platform) + [tmpfile])

See https://docs.python.org/2/library/shlex.html#parsing-rules

All 4 comments

Oh Windows, developing without you would be like vanilla ice cream without ketchup.

@MinchinWeb Can you test whether this works if we call silex with posix=False? Or rather,

subprocess.call(shlex.split(config['editor'], posix="win" not in sys.platform) + [tmpfile])

See https://docs.python.org/2/library/shlex.html#parsing-rules

@maebert , you crack me up... [mumbles to self] anyway, where's my ketchup?

Your code suggestion fixes the problem on my end (Windows 7, Python 3.4.3). I have prepped a pull request to take care of it (#349).

BAM! Thanks!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings