简体   繁体   English

从 Cygwin bash 脚本执行 Windows 命令

[英]Execute Windows command from Cygwin bash script

I am using Windows with Cygwin installed and have a bash script.我正在使用安装了 Cygwin 的 Windows 并有一个 bash 脚本。 Since Cygwin's implementation of the Unix cp command/program is flawed for Windows on default installation (fails to preserve Windows permissions unless Cygwin is installed with certain flags), I would like to issue Windows' native copy command from the bash script instead.由于 Cygwin 对 Unix cp命令/程序的实现在默认安装时对 Windows 存在缺陷(除非使用某些标志安装 Cygwin,否则无法保留 Windows 权限),我想改为从 bash 脚本发出 Windows 的本机copy命令。

Is there a way for me to issue this (and possibly any generic Windows Command Prompt command) and be able to handle errors (say copy fails due to UAC, file not found, network drive unreachable, etc.) from within the bash script?有没有办法让我发出这个(可能还有任何通用的 Windows 命令提示符命令)能够从 bash 脚本中处理错误(比如由于 UAC 导致copy失败、文件未找到、网络驱动器无法访问等)?

I don't have cygwin right now but one of the following should works我现在没有 cygwin,但以下之一应该有效

./test.bat params
cmd /c test.bat params
cmd /c copy /?

Remember the quotes/double quotes can be interpreted differently between cmd and bash .请记住,引号/双引号在cmdbash之间可以有不同的解释。

In Windows BAT :在 Windows BAT 中:

copy "YourFile.xyz" "ToDestinationPath(.xyz)" && (
              Echo Copy ==^> Success
                  ) || (
              Echo Copy ==^> Failed) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM