question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameter parsing bug on Windows

See original GitHub issue

The parameter parser doesn’t handle escaped characters correctly on Windows.

Running this works on Linux/MacOS, but fails on Windows:

streamlink -p /path/to/vlc -a "--input-title-format \"\\\"\" {filename}" STREAM best

This is related to chrippa/livestreamer#1337 (reported at streamlink/streamlink-twitch-gui#256 and streamlink/streamlink-twitch-gui#362)

I can’t remember if Linux/MacOS were affected by this in Livestreamer. Didn’t test it…

The error log:

[cli][info] Starting player: C:/Program Files (x86)/VideoLAN/VLC/vlc.exe
Traceback (most recent call last):
  File "C:\Program Files (x86)\Streamlink\bin\streamlink-script.py", line 12, in <module>
    main()
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 899, in main
    handle_url()
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 499, in handle_url
    handle_stream(plugin, streams, stream_name)
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 382, in handle_stream
    success = output_stream(stream)
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 259, in output_stream
    output.open()
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\output.py", line 21, in open
    self._open()
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\output.py", line 123, in _open
    self._open_subprocess()
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\output.py", line 138, in _open_subprocess
    self.player = subprocess.Popen(self._create_arguments(),
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\output.py", line 116, in _create_arguments
    return shlex.split(cmd) + shlex.split(args)
  File "shlex.py", line 273, in split
  File "shlex.py", line 263, in __next__
  File "shlex.py", line 90, in get_token
  File "shlex.py", line 166, in read_token
ValueError: No closing quotation

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
beardypigcommented, Jan 5, 2017

Right. As far as shlex is concerned this is the correct behaviour as it implements strict POSIX. From the IEEE Std 1003.1-2008, specifically section 2.2.2.

2.2.2 Single-Quotes Enclosing characters in single-quotes ( ‘’ ) shall preserve the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes.

In fact, you can reproduce it in sh, bash, zsh, plus any other POSIX compatible shell; you will find that there is still an open quote on the second line:

bash-4.4$ echo 'foo\'s'
> '
foo\s

So the correct thing to do is to always use " 😃

0reactions
beardypigcommented, Jan 5, 2017

I have added a test that reproduces this bug, and the most basic reproduction is:

assert shlex.split('--title "\\""') == ['--title', '"'] # passes
assert shlex.split("--title '\\''") == ['--title', "'"] # fails

Wether or not it can be easily fixed remains to be seen, as I workaround I would suggest always using " 😃 I will dig a bit deeper and see if a bug needs to be filed against the Python stdlibs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The command line parsing may erroneously parse ... - GitHub
Looking at the use of Windows Terminal, I speculate that this problem is caused by an error in parsing the command line. If...
Read more >
Parsing error when using variable as parameter value for ...
I'm using the following template: #TemplateWithParams.yaml parameters: - name: DatabaseServer type: string - name: InstanceId type: string steps: - script: ...
Read more >
How Command Line Parameters Are Parsed - David Deley
On Windows, the parameters are parsed off the command line after the new process is created, by the new process. It's considered the...
Read more >
Windows Bat file optional argument parsing - Stack Overflow
This solution provides Unix style arguments within a Windows batch. ... The parsing loop always looks for an option at %1 , and...
Read more >
ReportViewer bug: NullReference exception parsing null date ...
There appears to be a regression in recent datetime parsing changes to the Windows Forms Report Viewer control in NuGet package Microsoft.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found