除了进度之外,如何在命令行中使 robocopy 保持静默?
我正在使用 robocopy 通过 PowerShell 脚本进行备份,它非常棒,只是我希望它在复制时仅显示进度百分比,而不显示所有其他信息。
其他信息使命令窗口变得混乱,我将其清理干净,以便可以轻松查看备份的整体进度。
这可能吗?
I'm using robocopy to do backups with a PowerShell script, and it's pretty awesome, except that I'd like it to only show the progress percentage while it copies and not all of the other information.
The other information clutters the command window, which I'd clean and simple so that it's easy to see the overall progress of the backup.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我添加了以下2个参数:
/np /nfl
因此,结合
AndyGeek
答案中的 5 个参数,即/njh /njs /ndl /nc /ns
,您将得到以下内容无声无息:ROBOCOPY [source] [target] /NFL /NDL /NJH /NJS /nc /ns /np
I added the following 2 parameters:
/np /nfl
So together with the 5 parameters from
AndyGeek's
answer, which are/njh /njs /ndl /nc /ns
you get the following and it's silent:ROBOCOPY [source] [target] /NFL /NDL /NJH /NJS /nc /ns /np
我通过使用以下选项来做到这一点:
请注意,文件名仍然显示,但这对我来说很好。
有关
robocopy
的详细信息,请访问 https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopyI did it by using the following options:
Note that the file name still displays, but that's fine for me.
For more information on
robocopy
, go to https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy如果您根本不想输出,这是最简单的方法:
robocopy src dest > nul
如果您仍然需要一些信息并且只想删除部分输出,请使用 R.Koene 答案中的参数。
If you want no output at all this is the most simple way:
robocopy src dest > nul
If you still need some information and only want to strip parts of the output, use the parameters from
R.Koene's
answer.在 PowerShell 中,我喜欢使用:
它避免了记住所有命令行开关。
In PowerShell, I like to use:
It avoids having to remember all the command line switches.
robocopy 也倾向于打印空行,即使它不执行任何操作。我使用如下命令过滤掉空行:
robocopy also tends to print empty lines even if it does not do anything. I'm filtering empty lines away using command like this:
如果您希望它完全静默,一种解决方法是将输出重定向到文件(并且可以选择稍后将其删除)。
A workaround, if you want it to be absolutely silent, is to redirect the output to a file (and optionally delete it later).
我不确定它是否正确,但我在 Gitlab 中使用了它并且它有效:
I'm not sure if it is correct but I used this in Gitlab and it works:
的> null 在引号中不起作用。它看到 > null 作为批处理文件名。
robocopy 没有输出工作!
这是新的批处理文件:
The > null does not work in the quotes. It sees the > null as the batch filename.
The robocopy no output worked!!!
Here is the new batch file:
无需重定向到文件并稍后将其删除。
尝试:
There's no need to redirect to a file and delete it later.
Try: