我可以在没有可见命令提示符的情况下运行windows批处理文件吗?

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。...

我可以在没有可见命令提示符的情况下运行windows批处理文件吗?Batch files are a handy way to execute a series of commands in Windows, but is there anyway to run them invisibly in the background? Read on find out how.

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户读者Jake想隐形运行BAT文件,他写道:

I have installed a ruby gem called Redcar, which is launched from the command line. When it runs, it steals the shell until it terminates, so I have to create a new shell window to continue doing command line work. The shell I’m using is the GITBash shell from MySysGit.

I found a Redcar.bat file which is meant to launch Redcar as a shortcut, I presume, but I don’t want the extra command prompt window to open whenever I launch the BAT file.

How do I just run the BAT without seeing the prompt?

有什么办法可以解决杰克的隐秘欲望吗?

答案

超级用户贡献者Afrazier给出了坏消息和好消息的组合:

You can’t — executing a batch file with the built in Command Prompt is going to keep a window open until the batch file exits.

What you can do is take steps to make sure that the batch file exits as quickly as possible. If at all possible, modify the batch file to run whatever program with the start command. By default, start returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately. Couple that with modifying your shortcut to run the batch file minimized, and you’ll only see the taskbar flash without even seeing a window ***creen.

One caveat to this is that if you’re running a c***ole-mode program, which many script interpreters are, the batch file will wait for the program to exit, and using start will spawn a new c***ole window. What you need to do in this case is run the Windows-based version of the interpreter instead of the c***ole-based one — no start necessary. For Perl, you would run wperl.exe instead of perl.exe. For Python, it’s pythonw.exe instead of python.exe. The old win32 Ruby distribution I have downloaded has rubyw.exe, which should do the same thing.

A final possibility is to use a 3rd-party tool to run the command prompt with a hidden window. I’ve heard of such things but never had a use for them, so I don’t know of anything in particular to point you to.

读者还向他指出了另一个超级用户线程,该线程强调了如何使用visualbasic脚本来超越最小化可见性和完全隐藏CMD提示符的限制。在这篇文章中,Harry MC解释道:

Solution 1:

Save this one line of text as file invisible.vbs:

CreateObject(“Wscript.Shell”).Run “””” & WScript.Arguments(0) & “”””, 0, False

To run any program or batch file invisibly, use it like this:

wscript.exe “C:\Wherever\invisible.vbs” “C:\Some Other Place\MyBatchFile.bat”

To also be able to pass-on/relay a list of arguments use only two double quotes

CreateObject(“Wscript.Shell”).Run “” & WScript.Arguments(0) & “”, 0, False

eg: Invisible.vbs “Kill.vbs ME.exe”

Solution 2:

Use a command line tool to silently launch a process : Quiet.

根据您是否使用VBS和第三方工具的舒适程度,使用上述任何解决方案,都将至少降低CMD窗口的可见性或完全删除它。


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

 

  • 发表于 2021-04-12 03:23
  • 阅读 ( 199 )
  • 分类:互联网

你可能感兴趣的文章

如何在没有浏览器的情况下使用web

...服务器之间移动数据。需要更多吗?在PowerShell窗口的ftp提示符处键入help。 ...

  • 发布于 2021-03-11 17:22
  • 阅读 ( 258 )

如何解决Windows10中的com代理问题

...模式出现此问题,则应在计算机上运行一些扫描。在命令提示符下,使用SFC命令修复Windows文件,使用CHKDSK命令检查硬盘驱动器错误。 在命令提示符中重新注册几个DLL文件。在命令提示符下,运行命令regsvr32vbscript.d...

  • 发布于 2021-03-12 04:56
  • 阅读 ( 194 )

7个你永远无法理解的windows谜团

... 星号字符是命令提示符中的通配符,因此键入del*.*将删除当前目录中的所有文件。如果可以将文件命名为*.txt,则会与命令提示符中的del*.txt等命令冲突。键入该命令的人可能希望删除具...

  • 发布于 2021-03-14 02:33
  • 阅读 ( 231 )

文件扩展名指南:如何修复和批量重命名文件

... 请注意,您可能需要为xcopy命令运行提升的命令提示符(具有管理员权限)。在Windows10中,右键单击“开始”按钮并选择“命令提示符(Admin)”。您可以使用cd命令手动导航到文件夹,后跟文件夹路径,例如cd C:\Users\yo...

  • 发布于 2021-03-17 01:25
  • 阅读 ( 331 )

如何修复windows update错误0x80070057

... 右键单击“开始”菜单并选择“命令提示符(Admin)”,打开提升的命令提示符。现在运行以下命令: ...

  • 发布于 2021-03-17 19:13
  • 阅读 ( 354 )

如何在Windows10上检查您的windows体验分数

...然后选择“以管理员身份运行”。 当命令提示符打开时,输入以下命令:winsat formal 等待进程完成。完成后,您可以在C:\Windows\Performance\WinSAT\DataStore中找到XML文件。 查找一组包含运行...

  • 发布于 2021-03-17 21:40
  • 阅读 ( 332 )

如何修复windows10系统服务异常停止码

... 接下来,尝试从命令提示符下运行Windows Check Disk。CHKDSK是一个Windows系统工具,用于验证文件系统,并通过某些设置在运行时修复问题。它有助于处理许多Windows错误,包括DPC监视程序停止代码...

  • 发布于 2021-03-18 05:58
  • 阅读 ( 299 )

如何修复windows停止码内存管理bsod

...系统,并通过某些设置在运行时修复问题。您可以从命令提示符运行CHKDSK,它有很多漂亮的特性。 ...

  • 发布于 2021-03-18 06:51
  • 阅读 ( 244 )

我有32位还是64位窗口?下面是如何判断

... 2在命令提示符中使用命令 ...

  • 发布于 2021-03-20 09:57
  • 阅读 ( 212 )

如何在windows10中修复错误代码0x8000ffff

... 一个空白的命令提示符窗口将打开大约10秒钟。之后商店就要开门了。 ...

  • 发布于 2021-03-21 16:10
  • 阅读 ( 354 )
q957709418
q957709418

0 篇文章

相关推荐