如何在 Windows 的后台运行命令? [英] How to run a command in the background on Windows?

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

问题描述

在linux下你可以使用command &在后台运行command,shell下线后同样会继续.我想知道 windows 有没有类似的东西……

In linux you can use command & to run command on the background, the same will continue after the shell is offline. I was wondering is there something like that for windows…

推荐答案

我假设您想要做的是运行一个没有界面的命令(可能是自动的?).在 Windows 上,有许多选项可以满足您的需求:

I'm assuming what you want to do is run a command without an interface (possibly automatically?). On windows there are a number of options for what you are looking for:

  • 最好:将您的程序编写为 Windows 服务.这些将在没有人登录服务器时启动.它们让您选择用户帐户(可能与您自己的帐户不同),如果失败,它们将重新启动.它们始终运行,因此您可以在特定时间或定期从其中自动执行任务.有关如何编写 Windows 服务的更多信息,您可以在线阅读教程,例如 (http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx).

更好:启动命令并隐藏窗口.假设命令是 DOS 命令,您可以为此使用 VB 或 C# 脚本.请参阅此处了解更多信息信息.一个例子是:

Better: Start the command and hide the window. Assuming the command is a DOS command you can use a VB or C# script for this. See here for more information. An example is:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:yourbatch.bat"), 0, True

您仍然需要手动启动命令或编写任务来启动命令.这是该策略最大的跌幅之一.

You are still going to have to start the command manually or write a task to start the command. This is one of the biggest down falls of this strategy.

希望能帮到一些人!

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

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