Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: vbs how to execute a command with quoted parameters

10 Oct 2015   #1
live

Win7
 
 
vbs how to execute a command with quoted parameters

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 System SpecsSystem Spec
.
10 Oct 2015   #2
Alejandro85

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
10 Oct 2015   #3
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by Alejandro85 View Post
[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 System SpecsSystem Spec
.

11 Oct 2015   #4
live

Win7
 
 

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 System SpecsSystem Spec
11 Oct 2015   #5
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

I'm failing to make sense of your problem. What exactly are you trying to do?
My System SpecsSystem Spec
12 Oct 2015   #6
live

Win7
 
 

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 System SpecsSystem Spec
Reply

 vbs how to execute a command with quoted parameters




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
execute command at boot
Hi, I would like to execute a command at boot and repeat it until it succeeds. Does anyone know how I can achieve that ? For the moment, I run the command in the startup folder, so it does run just after user connection but, as it is a connection demand to another computer by ssh, if the...
General Discussion
Start Command Prompt and automatically execute a few commands
I am learning a programming language, and I frequently use command prompt to compile source codes, but every time I start command prompt I need to manually cd to the correct directory, and then I like to run cls to keep the window clean. I have looked around, but I'm not sure how to phrase a google...
Software
Meaning of Parameters in the XCOPY command
I'm trying to create bootable flash drives. At one point, I'm told to use the command, xcopy f:*.* /s/e/f hg: in which f: is the source, g: is the destination. Why am I told to type, "hg:"? What does the "h" do? When I enter the command, Windows 7 asks me if g: refers to a file or a...
General Discussion
Execute Last Command
scenario : 1. lmb to select a file or folder. 2. rmb to display context menu and choose 'rename'. 3. type new name. 4. lmb to select another file or folder 5. ... is there a way to program a key or a mouse button to automatically execute step 2 above? Or perhaps it's already one of my...
General Discussion
WBADMIN - command line parameters
Hi, WBADMIN command line parameters provides a possibility to create batch files running advanced, automated backup. But, I need a scheduled task for backup of the entire system image. It seems this is not possible, and that the only way to create a system image backup is by using the GUI?...
Performance & Maintenance
Game command line parameters
I simply want to add the -nointro parameter to my BioShock game shortcut. I go to the shortcut, then properties, but where I think it should be added, similar to what XP looks like, is greyed out (the word "BioShock"). What do I need to do? I'm new to Windows 7, coming from XP. Thanks, ...
Gaming


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:29.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App