HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.17k stars 654 forks source link

Sys.command fails when using quotes #10400

Open deepnight opened 3 years ago

deepnight commented 3 years ago

The following command fails for no reason:

Sys.command(' "path/to/some.exe" --arg "quotedArgument" ');

This seems to be related to the presence of double-quotes around both exe path and argument.

Workaround: use sys.io.Process:

var p = new sys.io.Process(' "path/to/some.exe" --arg "quotedArgument" '); // identical command
p.close();

For some reason, it seems like Sys.command implementation differs from sys.io.Process 🤔

deepnight commented 3 years ago

After some testing, it seems like when having multiple double-quotes, the command sent to the shell is "trimmed" by Sys.command:

"path/to/some.exe" --arg "quotedArgument"

becomes:

path/to/some.exe" --arg "quotedArgument
RealyUniqueName commented 3 years ago

Which target and OS?

deepnight commented 3 years ago

It was on Win10, and "no target": it was while using Haxe interpreter directly (for an Haxelib)

R32 commented 3 years ago

I found that if you directly run the following command from bash/ms-dos, an error will occurs

haxe -cp src -js bin/app.js --macro exclude("haxe.iterators.ArrayIterrator")

# (unknown) : Class<haxe.iterators.ArrayIterator> should be String
# (unknown) : ... For function argument 'pack'

But if you save the command to hxml file or use (') instead of (") then it will works normally

Edit: This should be another issue