以静默模式运行 CMD 或 BAT [英] Running a CMD or BAT in silent mode

查看:95
本文介绍了以静默模式运行 CMD 或 BAT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在静默模式下运行 CMD 或 .bat 文件?我希望防止向用户显示 CMD 界面.

How can I run a CMD or .bat file in silent mode? I'm looking to prevent the CMD interface from being shown to the user.

推荐答案

我在 StackOverflow 问题中提出了一种运行批处理文件的方法背景(不显示 DOS 窗口)

I have proposed in StackOverflow question a way to run a batch file in the background (no DOS windows displayed)

那应该可以回答你的问题.

That should answer your question.

这是:

从您的第一个脚本中,使用以下行调用您的第二个脚本:

From your first script, call your second script with the following line:

wscript.exe invis.vbs run.bat %*

实际上,您正在调用 vbs 脚本:

Actually, you are calling a vbs script with:

  • 脚本的[路径]名称
  • 脚本所需的所有其他参数 (%*)

然后,invis.vbs 将使用 Windows Script Host Run() 方法,需要:

Then, invis.vbs will call your script with the Windows Script Host Run() method, which takes:

  • intWindowStyle : 0 表示不可见的窗口"
  • bWaitOnReturn : false 表示您的第一个脚本不需要等待第二个脚本完成

查看完整 invis.vbs 脚本的问题:

See the question for the full invis.vbs script:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
                                                         ^
                             means "invisible window" ---| 

<小时>

在 Tammen 反馈后更新:


Update after Tammen's feedback:

如果您在 DOS 会话中并且想要在后台"启动另一个脚本,一个简单的 /b(如 上述相同的问题) 就足够了:

If you are in a DOS session and you want to launch another script "in the background", a simple /b (as detailed in the same aforementioned question) can be enough:

您可以使用 start/b second.bat 从共享第一个窗口的第一个批处理文件异步启动第二个批处理文件.

You can use start /b second.bat to launch a second batch file asynchronously from your first that shares your first one's window.

这篇关于以静默模式运行 CMD 或 BAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆