在后台运行批处理文件 [英] Run batch file in the background

查看:125
本文介绍了在后台运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,此批处理文件将不会自动启动,它只会当我双击运行就可以了。结果
我可以在后台运行的批处理文件,当我双击它。

I have a batch file, this batch file will not start automatically, it will only run when i double click on it.
Can I run the batch file in the background when I double click on it.

推荐答案

好了,你就可以开始将其与最小化启动,如果这是不够的。真的隐藏它是困难的(虽然我能想到的一个选项的现在)。

Well, you can start it minimized with start, if that is enough. Really hiding it is difficult (although I can think of an option right now).

基本上你需要确定该批次已通过双击它开始。您可以通过定义一个特殊变量做到这一点,寻找它:

Basically you need to determine whether the batch has been started by double-clicking it. You can do this by defining a special variable and look for it:

@echo off
if not defined FOO (
  set FOO=1
  start /min "" %~0
  exit /b
)

rem here whatever you wanted to do originally in the batch

只要 FOO 变量没有定义(这可能是默认几乎无处不在),此批将推出自己再次最小化,但的的第一个定义的变量。环境传递给子进程,这就是为什么这个工程。

As long as the FOO variable isn't defined (which is probably the default almost everywhere), this batch will launch itself minimized again, but with the variable defined first. Environments are passed to subprocesses, which is why this works.

这篇关于在后台运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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