AppVeyor中xcopy执行报参数错误,本地运行正常求排查方案
Let’s walk through practical fixes and debugging steps for this issue—since the command works locally but fails in AppVeyor’s shell environment, the problem likely stems from how the Unix-style shell interprets Windows command syntax.
Wrap xcopy in
cmd /cto let Windows handle parameter parsing
When running native Windows commands likexcopyfrom a sh shell, the shell’s parameter rules can clash with Windows expectations. Try modifying the command to use Command Prompt directly:cmd /c xcopy "$SITEPACKAGES\\google" "build\\lib\\google" /i /e /hThis ensures quotes and path separators are processed correctly by Windows’ native command line instead of the sh shell.
Verify the source directory exists before copying
Sometimesxcopythrows a "invalid parameters" error if the source path doesn’t exist (instead of a clearer "file not found" message). Add a check to confirm the directory is present:if [ -d "$SITEPACKAGES\\google" ]; then echo "Source directory exists: $SITEPACKAGES\\google" xcopy "$SITEPACKAGES\\google" "build\\lib\\google" /i /e /h else echo "ERROR: Source directory missing!" dir "$SITEPACKAGES" exit 1 fiThis helps rule out missing dependencies or broken installation steps in the AppVeyor environment.
Replace backslashes with forward slashes
Windowsxcopyaccepts forward slashes as path separators, and they avoid escape character headaches in sh scripts. Try rewriting the command like this:xcopy "$SITEPACKAGES/google" "build/lib/google" /i /e /hThis eliminates any potential misinterpretation of backslash escapes by the shell.
Enable shell debugging to inspect the actual executed command
Addset -xat the top of yourbuild-all.shscript to print every command as it runs. This will show you exactly how parameters are expanded and passed toxcopy, revealing issues like stripped quotes or unexpected path splitting.Trim hidden whitespace from the
$SITEPACKAGESvariable
Even if yourechooutput looks clean, there might be hidden leading/trailing whitespace in the variable in AppVeyor. Try trimming it before use:SITEPACKAGES_TRIMMED=$(echo "$SITEPACKAGES" | xargs) xcopy "$SITEPACKAGES_TRIMMED\\google" "build\\lib\\google" /i /e /hThis removes any whitespace that could misalign command parameters.
内容的提问来源于stack exchange,提问作者Yanone

