Closed roblabla closed 5 years ago
i liked your echo f |
solution better then have the copy directories broken.
this way we support both file copy and recursive dir copy. right?
I think so. I'm not super good at command-line windows stuff though, so don't take my word for it ^^'.
There are four scenarios off the top of my head that we need to support:
cp file file
will workcp -r directory directory
will workcp -r file file
should work (needs testing)cp file directory
should work (needs testing)ya, i'll check it out unless you want to check it out yourself and publish a PR? up to you
I already have a fix coded up using the first solution, since I needed a quick fix to make progress on my project. I'll investigate the above cases when I'm around a windows machine sometimes tonight.
Turns out, microsoft provides windows VM so I managed to test it right now. And the result is really sad:
C:\Users\IEUser\Desktop>xcopy /E desktop.ini test.ini
Cannot perform a cyclic copy
0 File(s) copied
So cp -r file file
would not work under the echo f | xcopy
solution.
More fun stuff:
C:\Users\IEUser\Desktop>mkdir test
C:\Users\IEUser\Desktop>xcopy desktop.ini test
0 File(s) copied
it seems xcopy file directory
does not work.
copy
has its own share of problem. It won't allow copying multiple files:
C:\Users\IEUser\Desktop>copy eula.lnk test.txt test
The syntax of the command is incorrect.
A stackoverflow solution:
for %I in (eula.lnk test.txt) do copy %I test
so.... if there is no good solution, maybe completely different approach. shell2batch tries to convert commands, but sometimes you might want to help it out. so what if we had something like the following
some command
another command
problematic command //shell2batch: dos command
meaning, if a line ends with some comment and a prefix, we take the rest of the line as the replacement command. so users could define a specific shell command line replacement but only for specific problematic lines.
mkdir -p somedir
cd somedir
cp a b //shell2batch: copy a b
echo whatever
also i wonder if /i
solves the xcopy issues?
/i
doesn't solve the xcopy
issue:
C:\Users\IEUser\Desktop>xcopy /i eula.lnk test2.txt
Does test2.txt specify a file name
or directory name on the target
(F = file, D = directory)?
Current discoveries, I'll edit this comment if I find any new ones:
cmd | echo f |
xcopy /copy |
for + xcopy /copy |
---|---|---|---|
cp file file |
✅ | ✅ | ✅ |
cp -r directory directory |
✅ | ✅ | ✅ |
cp -r file file |
🔴 | 🔴 | 🔴 |
cp file directory |
🔴 | ✅ | ✅ |
cp file1 file2 directory |
🔴 | 🔴 | ✅ |
cp -r dir1 dir2 directory |
🔴 | 🔴 | ✅ |
if a line ends with some comment and a prefix, we take the rest of the line as the replacement command.
Independently of this issue, this might be a good idea. It would help big scripts that need to differenciate only for a couple commands. So that's a big :+1: for me.
However, I still think we should try to find something that works for cp
. It's such a simple command, it'd be a shame if we couldn't find a good translation for it.
I'm currently thinking this: If it's a cp -r
, treat it as an xcopy
. If it's a non-recursive cp
, use copy
. And in both case, apply the for %I in (files) do copy %I dest
loop if there's more than one non-flag argument. I think this would make all the common cases of cp
work correctly.
(I'm half-tempted to attempt creating a shell2powershell to see if it's any simpler...)
i'm for doing the cp changes and in addition doing the hint (as separate issue). as for powershell.... i'm not sure since if i remember correctly, you can't run ps files as is. you need to first enable powershell running files via some policy command.
Describe the bug Currently, a copy of a single file, e.g.
cp linker-scripts/bootstrap.ld link.T
will generate the commandxcopy linker-scripts\bootstrap.ld link.T
. This command will prompt the user, staying stuck there forever:A simple way to avoid this would be to use
copy
forcp
without -r.cp
without-r
can only have files in source (directory sources are ignored), which is exactly what thecopy
command on windows is for. This way:With this solution,
cp -r file1 file2
will stay broken, but I think that's an okay trade-off to make. Alternatively,cp a b
could be turned intoecho f | xcopy a b
.Here's a stackoverflow link about the whole
xcopy
on single files issue: https://stackoverflow.com/questions/33752732/xcopy-still-asking-f-file-d-directory-confirmationTo Reproduce
From cargo-make: Make a folder with a
file1
file, then run the following Makefile.toml:It will hang until the user press F or D.