Win7 Runas命令:如何捕获正在运行的命令的输出? [英] Win7 runas command: How to capture output of command that is run?

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

问题描述

我正在尝试(在Windows 7下)使用runas命令停止然后重新启动服务. (Win7需要管理员priv才能执行此操作;因此需要使用runas.)

I'm trying (under Windows 7) to use the runas command to stop then restart a service. (Win7 requires admin privs to do this; thus the use of runas.)

停止服务可以正常运行,但是不能启动.这是我用来停止服务的命令:

Stopping the service works fine, but starting it does not. Here's the command I'm using for stopping the service:

runas /user:myDomain\myUserId "net stop serviceName"

以下是启动服务的命令:

Here's the command for starting the service:

runas /user:myDomain\myUserId "net start serviceName"

当我运行上面的命令时,另一个命令窗口打开,但是在我看到其中任何内容之前闪烁了;因此我不知道出了什么问题.

When I run the above command another command window opens, but flashes away before I can see anything in it; thus I have no idea what's going wrong.

所以,我的问题是:当通过runas运行时,如何从net start命令中捕获stdout和/或stderr?我试过只是使用重定向,但只是得到一个空文件.另一个解决方案是让runas打开窗口,以使子任务保持打开状态.

So, my question is: How might I capture stdout and/or stderr from the net start command when run via runas? I've tried just using redirection but just get an empty file. Another solution would be to get the window opened by runas for the subtask to remain open.

谢谢.

推荐答案

使用要运行的命令启动cmd.exe,并指定将输出写入文件.

Launch cmd.exe instead with the command to run, and specify that the output be written to a file.

runas/user:myDomain \ myUserId"cmd.exe/c网络停止服务名称> output.txt"

runas /user:myDomain\myUserId "cmd.exe /c net stop serviceName > output.txt"

您可以使用2>来从网络停止输出错误.

You can use 2> for error output from net stop.

这篇关于Win7 Runas命令:如何捕获正在运行的命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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