本文介绍了在CMD中运行PowerShell命令(带有管道)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在PowerShell中运行以下命令时:
When we run the following command in PowerShell:
get-date | sc C:\temp\date.log
它使用当前日期创建date.log文件。
it creates date.log file with current date.
但是如果我们通过CMD运行相同的命令:
But if we run the same via CMD:
powershell get-date | sc C:\temp\date.log
它抱怨:
DESCRIPTION:
SC is a command line program used for communicating with the
Service Control Manager and services.
USAGE:
sc <server> [command] [service name] <option1> <option2>...
显然,CMD混淆了管道的含义
Apparently, CMD confuses pipeline meant for POSH, with its own.
有人可以指出我如何通过CMD运行它吗?
Can anyone point me how to make it run via CMD?
谢谢
推荐答案
powershell -Command " & {Get-Date | sc c:\tmp\date.log}"
这篇关于在CMD中运行PowerShell命令(带有管道)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!