shubham gupta
shubham gupta

Reputation: 331

Running command line: can't find file

I'm trying to run a few commands from 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}"

But I get this error

biarimport.vbs(4, 1) (null): The system cannot find the file specified.

It seems pretty obvious that either lcm_cli.bat or LCMBiar_Import.property file is not there but it's not the case it's all there and it works fine if I directly run it through CMD.

Upvotes: 0

Views: 2705

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

Running a statement

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

does not change the working directory to that folder. It just spawns a CMD instance, which throws an error that the command C:\some\folder isn't recognized and then closes immediately (/c).

Because the working directory didn't change, the subsequent statment runs in the wrong working directory and thus can't find lcm_cli.bat:

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

Either use the CurrentDirectory property for changing the working directory:

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"

or run the batch script with its full path:

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"

Note that any path containing spaces must be put in nested double quotes when used in a Run statement (bot not with the CurrentDirectory property). Also, you don't need cmd /c for starting batch scripts. It's only required if you use CMD built-ins like dir or I/O redirection.

Upvotes: 1

Related Questions