remy / txt2bas

ZX Spectrum BASIC conversion tooling (specific support for NextBASIC)
19 stars 0 forks source link

Fails with an error with file-paths and filenames containing a space on Windows. #22

Closed TheStruggleForAntiSpaghetti closed 4 years ago

TheStruggleForAntiSpaghetti commented 4 years ago

S:\128 Banks Contention Test>call npx txt2bas -f tap -A 10 -i "S:\128 Banks Contention Test\128 Banks Contention Test.bas" -o "128 Banks Contention Test.tap" Error: ENOENT: no such file or directory, open 'S:\128' at Object.openSync (fs.js:440:3) at Object.readFileSync (fs.js:342:35) at main (C:\Users\Mike\AppData\Roaming\npm\node_modules\txt2bas\dist\cli\txt2bas.js:2776:14) at main$1 (C:\Users\Mike\AppData\Roaming\npm\node_modules\txt2bas\dist\cli\txt2bas.js:2906:3) at Object.<anonymous> (C:\Users\Mike\AppData\Roaming\npm\node_modules\txt2bas\dist\cli\txt2bas.js:2911:1) at Module._compile (internal/modules/cjs/loader.js:955:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10) at Module.load (internal/modules/cjs/loader.js:811:32) at Function.Module._load (internal/modules/cjs/loader.js:723:14) at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10) { errno: -4058, syscall: 'open', code: 'ENOENT', path: 'S:\\128' }

remy commented 4 years ago

Looks like an argument parsing failure.

You can get around it in the mean time by running the command in the same directory and rename your file so it doesn't have spaces.

I'll get a fix out for the bug too.

TheStruggleForAntiSpaghetti commented 4 years ago

It seems to choke on the folder name though so only renaming the filename won't do.

remy commented 4 years ago

Ah poo. I'll try to fix that soon - just requires that I dust off the windows machine to test!

remy commented 4 years ago

I've been looking at this a looking at this a bit more and I wanted to ask about the call at the start of the command. I suspect this is causing the args to the script to be broken up (incorrectly).

Node should read arguments contained in quotes without breaking it apart (and I use this in a highly used command line tool so I'm 99% sure it's "normally" fine).

Can you elaborate on the call command, and are you able to run npx without it?

TheStruggleForAntiSpaghetti commented 4 years ago

Sorry, just noticed your comment.

Without the call it's not returning to the batch file where it's called from and thus won't process the rest of the build script.

But that doesn't seem to be the issue.

When I enter directly from the command line: npx txt2bas -f tap -A 10 -i "S:\Bank contention test\128BanksContentionTest.bas" -o "128BanksContentionTest.tap"

it fails with: Error: ENOENT: no such file or directory, open 'S:\Bank'

It runs successfully when I remove the spaces from the folder name and adjust the parameter accordingly.

When I add a space in the filename, such as: npx txt2bas -f tap -A 10 -i "S:\Bankcontentiontest\128 BanksContentionTest.bas" -o "128BanksContentionTest.tap"

it again fails with the same error.

remy commented 4 years ago

So after some digging this turns out to be a long standing issue with npx. npx is failing to parse arguments with spaces in it. For context, npx is parsing the arguments (which include txt2bas, -f, and so on). npx does not see the quotation marks and treats the string as a separate argument.

There's a few work arounds:

  1. Install npm globally: npm install --global txt2bas - now you don't need to use npx and I've confirmed filenames with spaces work.
  2. Call txt2bas directly out of the node_modules directory: node_modules\.bin\txt2bas -f tap …
  3. Use the short filename instead of with spaces: https://stackoverflow.com/a/46871748/22617 (probably the worst option).

Sorry I couldn't be more help, but it looks like this problem is outside of txt2bas.

TheStruggleForAntiSpaghetti commented 4 years ago

Okay. Thanks for looking into it. Probably a good idea to include it in the documentation.

remy commented 4 years ago

Good shout.

On Tue, 28 Jul 2020, 20:03 TheStruggleForAntiSpaghetti, < notifications@github.com> wrote:

Okay. Thanks for looking into it. Probably a good idea to include it in the documentation.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/remy/txt2bas/issues/22#issuecomment-665220651, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADLBCVTC5ZARYA37T7RPDR54OHBANCNFSM4ONZTSMQ .