vseventer / sharp-cli

CLI for sharp.
MIT License
189 stars 20 forks source link

Input file specification on windows - Backslash #83

Closed regnete closed 1 year ago

regnete commented 1 year ago

Description

On a Windows cmd shell the input file (-i) cannot be specified with backslash in the path.

Reproduction

This command will not create out.jpg. It silently fails. sharp -i .\source.jpg -o ./out.jpg resize --width 800 --height 800

This command will create out.jpg. sharp -i ./source.jpg -o ./out.jpg resize --width 800 --height 800

Expected behaviour

Command sharp -i .\source.jpg -o ./out.jpg resize --width 800 --height 800 should create out.jpg

Remarks

toomanylogins commented 1 year ago

Do you know if absolute paths are accepted on Windows and Mac ? Something like in posix format

sharp -i F:/path with spaces/source.jpg -o F:/path with spaces/cache/thumb.jpg

vseventer commented 1 year ago

@regnete Under the hood, glob is used to grab the input files, which according to their docs requires: "Glob patterns should always use / as a path separator, even on Windows systems".

@toomanylogins Try quoting the arguments, e.g. sharp -i "F:/path with spaces/source.jpg" -o "F:/path with spaces/cache/thumb.jpg"

regnete commented 1 year ago

@regnete Under the hood, glob is used to grab the input files, which according to their docs requires: "Glob patterns should always use / as a path separator, even on Windows systems".

Thanks for this additional info. I assume that simply replacing \ with / when running on Windows platform won't fix this issue due to escaping/quoting and glob syntax requirements.

toomanylogins commented 1 year ago

Thanks for reply. I am doing as follows on win10 command prompt. No file is output and no error.

F:>cd youdocms_source\node

F:\youdocms_source\node>node sharp -i "F:/youdocms_source/node/test.jpg" -o "F:/youdocms_source/node/cache/test.jpg" resize 200 200

F:\youdocms_source\node>npm list node@ F:\youdocms_source\node +-- firebase-tools@0.1.6 +-- html-minifier@4.0.0 +-- html-to-text@9.0.4 +-- phpunserialize@1.3.0 +-- readability-checker@0.2.1 `-- sharp-cli@4.1.1

F:\youdocms_source\node>

regnete commented 1 year ago

@toomanylogins Exactly. The process should quit with an error code in this case.

process.exit(1);

vseventer commented 1 year ago

Makes sense - I'll generalize this and throw an error when there are no input files.