隐藏控制台而不丢失std err / out流 [英] Hiding the console without losing std err/out streams

查看:150
本文介绍了隐藏控制台而不丢失std err / out流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题类似于以静音模式运行CMD或BAT ,但附加一个限制。



如果您使用 WshScript.Run ,您将无法访问进程的/ error / out流中的标准。 WshScript.Exec 可让您访问标准流,但您不能隐藏您的窗口。



我目前正在考虑一个C ++可执行文件,它可以直接访问控制台流。创建新的Windows Station和桌面,(请参阅 MSDN < a>),并在该新桌面中运行指定的脚本(我还不是Windows工作站和桌面上的专家,所以这个想法可能会被延迟)。



想法是基于 Condor USE_VISIBLE_DESKTOP 功能,如果禁用,在不可见的桌面中运行Condor作业。



这种方法的权衡是,如果你的脚本在用户输入上阻塞,你的脚本可以消失。 p>

有没有其他想法?



此外,您也可以使用我们的脚本的目的是设置用户环境,所以作为另一个用户运行,或作为系统计划任务不是真的一个选项(除非有聪明的技巧,我不知道)。

解决方案

Cygwin( http:// www。 cygwin.com/ )附带一个名为run.exe的实用程序,它执行您要求的通用进程。你可以使用它来包装你的调用cscript。 Cygwin是GNU所以免费的商业或个人使用。


My question is similar to Running a CMD or BAT in silent mode, but with one additional constraint.

If you use WshScript.Run in vbscript, you lose access to the standard in/error/out streams of the process. WshScript.Exec gives you access to the standard streams, but you can't hide your windows. How can you have your cake (hide the windows) and eat it too (have direct access to the console streams)?

I'm currently thinking about a C++ executable which creates a new Windows Station and Desktop, (see MSDN) and runs a specified script within that new Desktop (I'm not yet an expert on Window Stations and Desktops, so this idea may be retarded).

This idea is based loosely on Condor's USE_VISIBLE_DESKTOP feature, which, if disabled, runs Condor jobs in a non-visible Desktop. I haven't quite figured out if this requires elevated priveledge.

The tradeoff of this approach is that your script can disappear into limbo if it blocks on user input.

Does anyone have any additional ideas? Or feedback on the approach outlined above?

Edit:

Also, the purpose of our script is to set up the user environment, so running as another user, or as a system scheduled task isn't really an option (unless there are clever tricks I don't know about).

解决方案

Cygwin (http://www.cygwin.com/) comes with a utility named run.exe which does what you are asking for a generic process. You could use this to wrap your call to cscript. Cygwin is GNU so free for commercial or personal use.

这篇关于隐藏控制台而不丢失std err / out流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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