vbs how to execute a command with quoted parameters

live

New member
Local time
10:28 AM
Messages
16
Hi,

OS: Win7 64bits Family

Can't find the way to fix quoting issue.

Suppose in the command prompt this works:

"c:\what ever\my program.exe" "d:\some dir\my file.txt" cat 1-2 output "d\some dir\_out.txt"

How do I make this into some vbs scripting?

I tried this:
Code:
exePath= "c:\what ever\my program.exe"
spath= "d:\some dir\"
iFile = spath & "my file.txt"
oFile= spath & "_out.txt"
iNumber=2

cli = Chr(34) & exePath & Chr(34) & " " & Chr(34) & sFileSelected  & Chr(34) & " cat 1-"& iNumber & " output  "  & Chr(34) & oFile & Chr(34)
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
Cmd=Chr(39) & cli & Chr(39) 
objShell.Run(Cmd)
Set objShell = Nothing

I get:
error 80070002 “The system cannot find the file specified”

Thanks
 

My Computer My Computer

OS
Win7
CPU
Intel
From a quick read, there is no variable named sFileSelected (as it's used in the concatenation).
Instead, it should be created from concatenating spath and iFile, declared earlier.
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
[sFileSelected] should be created from concatenating spath and iFile
And preferable using the 'BuildPath' method of the 'Scripting.FileSystemObject' com object.

The value of cli after line 7 is,
Code:
"c:\what ever\my program.exe" "" cat 1-2 output  "d:\some dir\_out.txt"
The second set of double quotes is missing its content. Consider replacing sFileSelected with 'spath & iFile', or define the variable sFileSelected as such before you reference it, Live.
 

My Computer My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Oups, I wanted to make it simpler than actually (opens a file selection window)

The line being, but doesn't change anything to the issue:
Code:
cli = Chr(34) & exePath & Chr(34) & " " & Chr(34) & iFile & Chr(34) & " cat 1-"& iNumber & " output  "  & Chr(34) & oFile & Chr(34)
 

My Computer My Computer

OS
Win7
CPU
Intel
I'm failing to make sense of your problem. What exactly are you trying to do?
 

My Computer My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Code:
What exactly are you trying to do?
Execute some command line tools having quoted parameters from a vbs script (bat file).

the error was:
Cmd=Chr(39) & cli & Chr(39)

Doesn't need to be quoted
 

My Computer My Computer

OS
Win7
CPU
Intel
Back
Top