Re: Shell Command Doesn't Create TXT file as expected
- From: "Bob Butler" <tiredofit@xxxxxxxxxx>
- Date: Tue, 6 Sep 2005 09:29:41 -0700
"Andibevan" <Andibevan@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:OtKEb7vsFHA.908@xxxxxxxxxxxxxxxxxxxx
> Hi All,
>
> I am having problems using the shell command to write the output of a
> dos command to a text file.
>
> I would be really grateful if someone could tell me why this doesn't
> produce the required Test.txt file?
>
> Sub Test
>
> Shell ("dir >C:\test.txt")
>
> End sub
>
> I get the error "File Not Found"
Shell runs executables and there is no "dir.exe" or "dir.com" to run. What
you are trying to do is start the command environment and then execute the
dir command in that. You also need the command environment to handle
redirection. Try this:
shell environ$("comspec") & " /c dir > c:\test.txt", vbNormalFocus
Two other notes:
* don't use () around the arguments unless you are using the CALL keyword or
storing the retunr value. It is either
Shell <arguments>
or
Call Shell(<arguments>)
or
x=Shell(<arguments>)
When you mix the first two formats as you are doing it may work, may give
you a syntax error and may do something you did not intend depending on the
specific situation.
* you can get a list of files using the Dir function (along with
FileDateTime and FileLen) so there isn't really any need to Shell a 'dir'
command in most cases.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
.
- References:
- Shell Command Doesn't Create TXT file as expected
- From: Andibevan
- Shell Command Doesn't Create TXT file as expected
- Prev by Date: Re: Shell Command Doesn't Create TXT file as expected
- Next by Date: Re: Lost VB6.0 Professional CD
- Previous by thread: Re: Shell Command Doesn't Create TXT file as expected
- Next by thread: Re: Shell Command Doesn't Create TXT file as expected
- Index(es):
Relevant Pages
|