从 VBScript 调用 Ruby [英] Call Ruby from a VBScript
问题描述
嘿,我最近一直在使用 ruby
和 vbscript
.有一种情况,我需要从另一个 vbscript
调用 ruby 脚本,但我被困在那里.我试过这段代码,
Hey I have been working with ruby
and vbscript
lately. There is a scenario where I need to call a ruby script from another vbscript
and I am stuck there. I tried this code,
Set newobj = CreateObject("WScript.shell")
obj = newobj.Run("ruby E:\rubyfile.rb > D:\newdoc.txt",1,true)
但是 ruby 脚本没有给出结果.我做得对还是有其他方法可以做到?如果单独执行 ruby 脚本,则生成结果,所以问题不在于 ruby 脚本.
but the ruby script is not giving the result. Am I doing it right or is there some other way to do it? If the ruby script is executed separately then the results are generated, so the problem is not with the ruby script.
推荐答案
你需要一个 shell (%comspec%/c
) 来获得一个 shell 的功能,比如 >
重定向.所以改变
You need a shell (%comspec% /c
) to get a shell's feature like >
redirection. So change
obj = newobj.Run("ruby E:\rubyfile.rb > D:\newdoc.txt",1,true)
到
nRet = newobj.Run("%comspec% /c ruby E:\rubyfile.rb > D:\newdoc.txt",1,true)
(研究 .Run 文档 查看使用 nRet
而不是 obj
的原因,并思考newobj"这个名字的糟糕之处)
(Study the docs for .Run to see the reason for nRet
instead of obj
and spend a thought on the lousy-ness of the name "newobj")
这篇关于从 VBScript 调用 Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!