FastCopyLab / FastCopy

158 stars 4 forks source link

`/include` switch does work correctly in cmd but not in powershell #292

Closed tukanos closed 4 months ago

tukanos commented 4 months ago

Describe the bug An executed command in cmd.exe works correctly, but the equivalent command does not work correctly in PowerShell 7.4.0.

To Reproduce I wanted FastCopy to copy only .7z and .7z.sha256 files so I did the following:

Here the files are correctly copied to the destination.


Nothing is copied to the destination.

**Command line options and various settings**
Nothing (using std. cmd.exe and pwsh.exe)

**Version/Environment**
 - FastCopy ver 5.7.3
 - OS ver: Windows Server 2022 with up to 02-2022 cumulative update
shirouzu commented 4 months ago

I don't think this is an issue with FastCopy, but rather an issue with how you use PowerShell. How about looking at the differences in the lines in fastcopy.log when running with cmd.exe and PowerShell.exe?

tukanos commented 4 months ago

I don't think this is an issue with FastCopy, but rather an issue with how you use PowerShell. How about looking at the differences in the lines in fastcopy.log when running with cmd.exe and PowerShell.exe?

I dug deeper into this issue as it seems weird there is some kind of interaction between FastCopy and PowerShell that does not work correctly (it is hard to say where actually the bug is, without debugging it with debugger). I have even found what is causing the issue when using FastCopy and PowerShell splatting

I did, of course, look at the fastcopy.log and the difference was that that CMD copied everything correctly and the above powershell script did not copy anything.

I tried every single supported way how to execute an executable in the powershell. I found a way in which it works.

For future reference using hashtable and start-process:

$processOptions = @{
    FilePath = 'C:\app\FastCopy\fcp.exe'
    ArgumentList = '/cmd=noexist_only','/include="*.7z*"','/no_ui','/no_confirm_stop','/verify'
    RedirectStandardOutput = "FastCopyStdOutput.txt"
    RedirectStandardError = "FastCopyError.txt"
    UseNewEnvironment = $true
}
$processOptions.'ArgumentList' += '/logfile=X:\Pohoda_MSSQL_zalohy\test\FastCopy.log'
$processOptions.'ArgumentList' += 'C:\t\PohodaSQL\Data','/to=X:\Pohoda_MSSQL_zalohy\test'

Start-Process @processOptions

However, the splatting is broken with FastCopy and the culprit seems to be the filtering /include="*.7z*". So even when I use stop parsing input as powershell command or expression for FastCopy it does not work:

& C:\app\FastCopy\fcp.exe --% /cmd=noexist_only /include="*.7z*" /no_ui /no_confirm_stop /verify /logfile=X:\Pohoda_MSSQL_zalohy\test\FastCopy_splat.log C:\t\PohodaSQL\Data /to=X:\Pohoda_MSSQL_zalohy\test

That should work, but hard to say if that is FastCopy's or PowerShell's fault, but it is certainly something to be aware of.