Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell Command and spaces in multiple parameters.

Status
Not open for further replies.

ammiller

Programmer
Nov 21, 2002
8
IE
Hi,

I have searched the forums and have got a partial answer to the following - but not fully.

First I wanted to run a batch file from a shell command, where there were spaces in the file path. I done this by doing the following:

dim x
dim shell_cmd
shell_cmd = _
chr(34) & "c:\folder with space\batchfile.bat" & chr(34)
x = shell(shell_cmd, 1)

This runs fine.

The next step is I want to pass in a log file as a parameter.

This works fine if there are no apaces in the log file, such as:

dim x
dim shell_cmd
shell_cmd = _
chr(34) & "c:\folder with space\batchfile.bat" & chr(34) & _
"c:\log_file.txt"
x = shell(shell_cmd, 1)


So my problem is where the parameter has a space in the folder name such as "c:\folder with space\log_file.txt"

I have tried many variations without success - but initially thought the way to go was:

dim x
dim shell_cmd
shell_cmd = _
chr(34) & "c:\folder with space\batchfile.bat" & chr(34) & _
" " & chr(34) & "c:\folder with space\log_file.txt" & _
chr(34)
x = shell(shell_cmd, 1)

The batch file is using this parameter as a log file - so every command is followed by ">>%1".

But it doesn't run. The batch file is called, but it fails to interpret the log file as a parameter.

Anyone with any ideas?
I really do think I have exausted all variations.
Apart from getting the business to not have spaces in their folder names, an alternative would be to define the folder path in the actual batch file and only pass in the log file name, then append the 2 in the batch file - but as the vb code will be calling about 30 different batch files, I want to maintain the folder in the vb code and pass it in.

Thanks

Aidan
 
Hi Aidan,

Spaces in Folder/File names can be a royal pain at times.

One thing you might try is using the old 8.3 folder / file name.
Your Folder With Space would be something like Folder~1.
You can see the 8.3 names by opening a Command Prompt (DOS Prompt) and typing DIR /X. The /X switch works in Windows XP (not sure about other OS).

Ken
 
Ken - thanks for responding.

I don't really understand how to go about this though.

Where do I define "My folder with space" as "My~1"?

I'm sorry to sound so stupid.


Aidan
 
You should be able to re-write the shell_cmd variable from your code as follows:

shell_cmd = "c:\folder~1\batchfile.bat c:\folder~1\log_file.txt"

You don't need the chr(34) anymore because there are no spaces in the path-filenames.

Just make sure that folder~1 is the correct 8.3 name for the 'folder with space' folder by doing the DIR /X thing.

Ken
 
Ken,

This has solved my problem.
Thanks for taking the trouble to reply.

Aidan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top