Re: Shell Command Doesn't Create TXT file as expected



"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..."

.



Relevant Pages

  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exeâ ...
    (comp.os.linux.misc)
  • Re: Great SWT Program
    ... None of the nasty things that you have said or implied about me are at ... treat the file as input (manually invoking the command interpreter ... script, copy the line into that within the editor, exit, and invoke ... the shell script. ...
    (comp.lang.java.programmer)
  • Re: ksh silently ignores function if mistakenly not autoloaded
    ... Here's the order of execution. ... This really takes place prior to command ... Shell scripts, with all their power, have one major drawback - they ... In the Korn Shell, there are two separate syntaxes for defining ...
    (comp.unix.shell)
  • Re: Shell function - accessing an Access secure db (.MDW file)
    ... > Hi - Does anyone know the correct syntax for the shell function. ... You can use the Shell command. ... To execute internal DOS command (Dir, Copy, ... Private Declare Function OpenProcess _ ...
    (microsoft.public.vb.general.discussion)