TIL escaping things for cmd.exe is sometimes impossible

like, if you have a file:

C:\folder with spaces (And parens)\fancy!!! chars'`@;,[]{}().txt

the only way to get that escaped as a subshell in bash is like:

cat "$(wslpath $'C:\\folder with spaces (And parens)\\fancy!!! chars\'`@;,[]{}().txt')"

and i'm trying to write something that will throw this into bash.exe -ic, but how the heck do you escape it?

backslashes won't do it, carets don't do it

looking it up, turns out you can't??

i even wrote a C# program to use its built-in argument parsing, so *it* could figure out passing that as a single argument to wsl bash

it couldn't do it either

i did figure out a way to do it though! and that way is very bad, hee

i base64 the whole command line, and run it in a subshell, because that doesn't require any double-quotes or escaping magic cmd-side

it's unfortunate that i'm relying on base64 existing in any wsl that this is used in, but i guess i'm already relying on bash as it is anyway, soooo....

always happy to come across another situation that's "not such a big deal because it's simply a contrived problem which you'll likely never encounter."

(from superuser.com/a/962805/149426)

oh yeah! i guess i should mention this is for wsl_proxy!

it's a thing i'm making that lets you use wsl command line tools as if they were windows programs

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!