如何在一行中运行命令两次?

huangapple go评论51阅读模式
英文:

CMD - How do I run a command twice in one line?

问题

systeminfo | find /i "host name" && systeminfo | find /i "boot time"

英文:

How do I display both the host name and boot time?
The code I'm trying:

systeminfo | find /i "host name" && "boot time"

I know I could use

systeminfo | find /i "host name"

systeminfo | find /i "boot time"

but I really don't want to.

Basically I want the command to display the host name and boot time and ignore all else. How do I do that on one line? I know I'm missing something super simple here.

答案1

得分: 0

我之前遇到过类似的问题,也许我可以帮助你。如果我正确理解你的问题,你想要一行中同时显示主机名和启动时间,使用一个单一提示。在这种情况下,以下命令应该能满足你的需求,当然忽略花括号:

{systeminfo | find /i "host name" & systeminfo | find /i "boot time"}

使用 & 字符将依次执行两个 systeminfo 命令并将结果输出在同一行上。

祝你在项目中一切顺利。如果需要任何其他帮助,请告诉我。

英文:

I have faced a similar problem before, and I may be able to help you out. If I understand your question correctly, you're looking for a way to display both the host name and boot time on one line, using a single prompt. In that case, the following command should do the trick, ignore the curly brackets of course:

{systeminfo | find /i "host name" & systeminfo | find /i "boot time"}

Using the & character will execute the two systeminfo commands sequentially and output the results on the same line.

I wish you the best of luck with your project. Let me know if I can help with anything else.

答案2

得分: 0

我强烈建议不要运行Windows上最慢的实用程序systeminfo.exe来获取这种类型的信息。

如果您愿意,可以尝试使用一个不那么占用资源且更快的实用程序net.exe

您还应该尽量不要期望实用程序以特定语言输出字符串。

示例:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "CN=" & For /F "EOL= Delims=" %%G In ('(%SystemRoot%\System32\net.exe
 Stats Srv 2>NUL || %SystemRoot%\System32\net.exe Stats Work^) ||
 %SystemRoot%\System32\findstr.exe /ELV ".") Do If Not Defined CN (
    Set "CN=%%~nxG") Else For %%H In (%%G) Do (SetLocal EnableDelayedExpansion
    For %%I In ("!BT!") Do EndLocal & Set "BD=%%~I" & Set "BT=%%H")

If Defined CN Echo %CN% was booted on %BD% at %BT%& Pause
英文:

I would strongly advise against running the slowest utility on Windows, systeminfo.exe, just to get this type of information.

You could, if you wish try to use a less intensive, and quicker utility, net.exe.

You should also try to not to expect utilities to output strings in a specific language.

Example:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "CN=" & For /F "EOL= Delims=" %%G In ('(%SystemRoot%\System32\net.exe
 Stats Srv 2^>NUL ^|^| %SystemRoot%\System32\net.exe Stats Work^) ^|
 %SystemRoot%\System32\findstr.exe /ELV "."') Do If Not Defined CN (
	Set "CN=%%~nxG") Else For %%H In (%%G) Do (SetLocal EnabledelayedExpansion
	For %%I In ("!BT!") Do EndLocal & Set "BD=%%~I" & Set "BT=%%H")

If Defined CN Echo %CN% was booted on %BD% at %BT%& Pause

huangapple
  • 本文由 发表于 2023年2月16日 08:35:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定