sagiegurari / shell2batch

Coverts simple basic shell scripts to windows batch scripts.
Apache License 2.0
57 stars 7 forks source link

cp fails on windows when the path comes from variables #18

Closed starccy closed 2 years ago

starccy commented 2 years ago

Problem

On Windows cmd, copy would fail when the path contains /, they should be converted to \.
I see there has been implemented: Convert '/' to '\' in command arguments.
However, it still can lead to errors while using variables, because slash inside variables will not be converted.

To Reproduce

Here is a minimal Makefile.toml to reproduce.

[env]
A_PATH = "folder/inner/test.txt"

[tasks.cp1]  # it's okey
script_runner = "@shell"
script = """
cp folder/inner/test.txt ./
"""

[tasks.cp2] # error because ${A_PATH} will be replace by `folder/inner/test.txt ` without slash converted.
script_runner = "@shell"
script = """
echo ${A_PATH}
cp ${A_PATH} ./
"""

output: [cargo-make] ERROR - Error while executing command, exit code: 1

sagiegurari commented 2 years ago

for this use case i suggest duckscript, since basically the variable expansion is up to the OS to do

[tasks.cp2]
script_runner = "@duckscript"
script = """
echo ${A_PATH}
cp ${A_PATH} ./test.txt
"""

if its a glob, take a look at glob_cp

starccy commented 2 years ago

Thanks for your advice, I would check it out.

sagiegurari commented 2 years ago

closing this for now since i think we have a better solution.