By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,945 Members | 1,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,945 IT Pros & Developers. It's quick & easy.

SHELL to a batch file?

P: n/a
MLH
SHELLing to run a batch file in a cmd window does not work
with all batch files. Here are two examples...

c:\windows\Doc_Dirs.bat ==DIR *. /s WinDirs.txt
- and -
c:\db\timnall\getconf.bat ==ipconfig /all >c:\IPoutput.txt

I've been shelling out to the latter for almost 2 years - never
a problem. I've never been able to successfully SHELL out
and run the former. I've tried with VBA's SHELL and with
Terry Kreft's SHELLWAIT. I've tried using the following syntax:
Shell(Environ$("Comspec") & " /c " & strShell, vbNormalFocus)
No luck.

The batch files have 2 differences worth noting:
Doc_Dirs.bat involves a lot more disk access and generally
takes a great deal more time to run than GetConf.bat. Can
anyone offer a SHELLing solution for the first batch file?
Sep 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Yes it does work, you just don't understand how it's working.

Change your first bat file to

c:
cd c:\windows
DIR *. /s WinDirs.txt

or alternatively
DIR c:\windows\*. /s c:\windows\windirs.txt

Then look at your second bat file and see if you can spot what is wrong.

--

Terry Kreft
"MLH" <CR**@NorthState.netwrote in message
news:24********************************@4ax.com...
SHELLing to run a batch file in a cmd window does not work
with all batch files. Here are two examples...

c:\windows\Doc_Dirs.bat ==DIR *. /s WinDirs.txt
- and -
c:\db\timnall\getconf.bat ==ipconfig /all >c:\IPoutput.txt

I've been shelling out to the latter for almost 2 years - never
a problem. I've never been able to successfully SHELL out
and run the former. I've tried with VBA's SHELL and with
Terry Kreft's SHELLWAIT. I've tried using the following syntax:
Shell(Environ$("Comspec") & " /c " & strShell, vbNormalFocus)
No luck.

The batch files have 2 differences worth noting:
Doc_Dirs.bat involves a lot more disk access and generally
takes a great deal more time to run than GetConf.bat. Can
anyone offer a SHELLing solution for the first batch file?

Sep 29 '06 #2

P: n/a
MLH
Thx! Will have a go at it.

I created c:\windows\DOC_DIRS.COM
from the bat file as originally posted.
Interestingly enough, it runs fine from
the START, RUN dialog box. Of course,
the bat file failed to run from there.
Sep 29 '06 #3

P: n/a
MLH
Well, Terry, it worked perfectly -
just like you said it would. Would
you help me understand why the
3 short, concise lines work in a
SHELL environment and 1 heavier
laden line does not?
Sep 29 '06 #4

P: n/a
Because when you shell out to a command shell it gets a copy of your dos
command environment, this includes the current folder and hence the current
drive, which may well be different from what you get in the Windows shell.

In other words your bat file was working but it was starting somewhere
different to where you thought it was starting and therefore creating the
file somewhere different.

--

Terry Kreft
"MLH" <CR**@NorthState.netwrote in message
news:qk********************************@4ax.com...
Well, Terry, it worked perfectly -
just like you said it would. Would
you help me understand why the
3 short, concise lines work in a
SHELL environment and 1 heavier
laden line does not?

Sep 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.