#Weird behavior around tauri.spawn in windows

14 messages · Page 1 of 1 (latest)

cold junco
#

I have a cmd that I have to invoke, it receives a string argument that is quoted and looks like "${path}". On MacOS and seemingly Linux everything works fine.
But on windows machines backslashes are appended and prepended to the string. So instead of somecmd "path/to/thing.ext" like on other systems. I get somecmd "\path\to\thing.ext\"
Why?
How can I solve this?
Is this a bug?
Is this a bug on my end?

hallow cobalt
#

How do you assemble the path? A short snippet of example code would help to understand the problem.

cold junco
#

simplified, but

const path = await fs.writeFile("something", { cwd: SomeDir })
await new Command("my-cmd", `"${path}"`, { cwd: SomeDir }).spawn()
hallow cobalt
#

fs.writeFile should return void, unless that isn't Tauri's fs module.

cold junco
#

sorry,

const path = await fs.writeFile("something.ext", { cwd: SomeDir })
await new Command("my-cmd", `"something.ext"`, { cwd: SomeDir }).spawn()
hallow cobalt
#

I don't see anything wrong with that input. Have you checked that SomeDir and the string-literal (that I presume is a variable named path from the first code block) don't have those slashes?

cold junco
#

It absolutely does not have slashes

#

It was checked

hallow cobalt
#

What version of Tauri are you using? 1.4 or 2.0.0-alpha.10?

#

Sorry, 1.4.1 is the latest.

cold junco
#

1.4

hallow cobalt
#

I'll take a look at this but won't be able to get back to you immediately.

hallow cobalt
#

TL;DR double-quotes (") can cause problems as their behaviour is inconsistent between platforms. Unix-like systems (Linux and macOS) transform arguments, while Windows simply sends them to the program to figure out.

Discord has some formatting limitations on nested backticks so I've put the literals in a code block at the end with the [#] referring to the line number within the code block.
On Linux, [1] in config and [2] in JS becomes equivalent to running [3] in bash. The program will see it as [4].
On Windows, [6] in config and [7] in JS becomes equivalent to running [8] in Command Prompt. Windows' more will see it as two separate strings like [9], but a Go program will see [10].

/usr/bin/grep
`"hi spaced"`, { cwd: "/home/icb/Documents" }
cd /home/icb/Documents && "/usr/bin/cat" "\"hi spaced\""
"hi spaced"

C:\\Windows\\System32\\more.com
`"hi spaced"`, { cwd: "C:\\Users\\icb\\Documents" }
cd C:\Users\icb\Documents && "C:\Windows\System32\more.com" "\"hi spaced\""
["hi", "spaced"]
"hi spaced"
cold junco