vbs运行命令无输出 [英] vbs run command no output

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

问题描述

好的,我创建了一个小脚本来调用网络文件"并将输出泵送到一个文件中.文件名中没有空格,当我以交互方式运行它时,一切似乎都没有问题.所以我运行以下命令,但没有得到任何结果,也没有错误:

Okay I created a small script to call "net file" and pump the output to a file. There are no spaces in the filenames, and everything seems okay when I run it interactively. So I run the following and I get no results and no errors:

set oWShell = CreateObject("WScript.Shell")
owshell.run "net file > C:\openfiles.txt"
Set owShell = nothing

现在,如果稍微修改它以显示执行相同的命令(并保持我的命令窗口打开)它会按预期工作(除了它保持我不能打开的 cmd 窗口)

Now if modify this just slightly to show execute the same command (and keep my command window open) it works just as expected (except it keeps the cmd window open which I can't have)

set oWShell = CreateObject("WScript.Shell")
owshell.run "%comspec% /k net file > C:\openfiles.txt"
Set owShell = nothing

很明显,我只是错过了一些东西.我只在蓝月亮中接触过一次 vbs,所以我不习惯使用它.

It must be something obvious that I'm just missing. I only touch vbs once in a blue moon so it isn't something that I'm that used to using.

任何帮助将不胜感激!提前致谢!

Any help would be appreciated! Thanks in advance!

推荐答案

你需要一个 shell(即 %comspec%)来获得像重定向这样的 shell 功能;持久窗口是您要求的:/k 让外壳保持打开状态(尝试/c 代替),您应该使用 .Run 方法的第二个和第三个参数来获取隐藏窗口(并可能在此之前等待进程你关闭了 owShell).

You need a shell (i.e. %comspec%) to get shell features like redirection; the persisten window is what you asked for: the /k lets the shell stay open (try /c instead) and you should use the second and third parameter of the .Run method to get a hidden window (and possibly wait for the process before you zap the owShell).

这篇关于vbs运行命令无输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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