2016-01-12 52 views
0

我试图运行从VBScript几个命令:运行命令行:找不到文件

Dim objShell 
Set objShell = WScript.CreateObject("WScript.shell") 
objShell.Run "cmd /c C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win64_x64\scripts" 
objshell.Run "lcm_cli.bat -lcmproperty C:\LCMBiar_Import.property" 
WScript.Sleep 500 
wshshell.SendKeys "{ENTER}" 

但我得到这个错误

biarimport.vbs(4,1) (空):系统找不到指定的文件。

似乎很明显,无论是lcm_cli.batLCMBiar_Import.property文件不存在,但它不是这一切都没有的情况下,如果我直接通过CMD运行它,它工作正常。

+0

请创建一个[mcve]。 – Heinzi

回答

0

运行语句

objShell.run "cmd /c C:\some\folder" 

的工作目录不会更改该文件夹。它只是产生一个CMD实例,该实例抛出一个错误,指令C:\some\folder未被识别,然后立即关闭(/c)。

因为工作目录没有改变,后续statment在错误的工作目录下运行,因此无法找到lcm_cli.bat

objshell.run "lcm_cli.bat -lcmproperty C:\LCMBiar_Import.property" 

要么使用CurrentDirectory属性改变工作目录:

objShell.CurrentDirectory "C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win64_x64\scripts" 
objshell.Run "lcm_cli.bat -lcmproperty C:\LCMBiar_Import.property" 

或完整路径运行批处理脚本:

objShell.Run """C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win64_x64\scripts\lcm_cli.bat"" -lcmproperty C:\LCMBiar_Import.property" 

请注意,在Run语句(机器人不属于CurrentDirectory属性)中使用时,必须将包含空格的任何路径置于嵌套双引号中。另外,您不需要cmd /c来启动批处理脚本。仅当您使用CMD内置插件(如dir或I/O重定向)时才需要。

+0

嗨,我知道你在说什么,并在一个objShell.run中将我的命令召集到一起“cmd/c cd C:\ Program Files(x86)\ SAP BusinessObjects \ SAP BusinessObjects Enterprise XI 4.0 \ win64_x64 \ scripts&lcm_cli.bat -lcmproperty C:\ LCMBiar_Import.property“ –

+0

但是,此命令”lcm_cli.bat -lcm ...“要求我按Enter键继续!任何想法如何做到这一点 –

+0

这是一个不同的问题,所以请将其作为一个新问题发布。 –

相关问题