我正在使用Windows批处理完成一个编程作业。我们需要检索以下信息:
- c:驱动器的可用空间大小(以字节为单位)
- 处理器时间的百分比
- 内存容量(以字节为单位)
以下是我的答案:
dir C:\ | find "Dir(s)"
wmic cpu get loadpercentage
wmic memorychip get capacity
我们还被要求将所有这些内容输出到单个文本文件中。我没有太多使用批处理命令的经验。是否有一种简单直接的方法可以实现这一点?
我正在使用Windows批处理完成一个编程作业。我们需要检索以下信息:
以下是我的答案:
dir C:\ | find "Dir(s)"
wmic cpu get loadpercentage
wmic memorychip get capacity
我们还被要求将所有这些内容输出到单个文本文件中。我没有太多使用批处理命令的经验。是否有一种简单直接的方法可以实现这一点?
> file_out.log(command + command + command)
或其变体::
(
dir C:\ | find "Dir(s)"
"%__APPDIR__%wbem\wmic" cpu get loadpercentage
"%__APPDIR__%wbem\wmic" memorychip get capacity
) >d:\path\file_name.log
rem :: or ...
>d:\path\file_name.log (
dir C:\ | find "Dir(s)"
"%__APPDIR__%wbem\wmic" cpu get loadpercentage
"%__APPDIR__%wbem\wmic" memorychip get capacity
)
rem :: or ...
>d:\path\file_name.log (dir C:\ | find "Dir(s)" & "%__APPDIR__%wbem\wmic" cpu get loadpercentage & "%__APPDIR__%wbem\wmic" memorychip get capacity)
rem :: or ...
(dir C:\ | find "Dir(s)" & "%__APPDIR__%wbem\wmic" cpu get loadpercentage & "%__APPDIR__%wbem\wmic" memorychip get capacity) >d:\path\file_name.log
完成此操作的最佳方式是使用>
和>>
命令,其中:
">" means : (re)create the file and write inside it. (If the file already exists, delete it first)
">>" means : append to the file.
dir C:\ | find "Dir(s)" > C:\whatever_directory\outputfile.txt
wmic cpu get loadpercentage >> C:\whatever_directory\outputfile.txt
wmic memorychip get capacity >> C:\whatever_directory\outputfile.txt
/OUTPUT
和/APPEND
,您可能会发现它们很有用。 - Compo