Re: Batch scripting, special character

From: Norman Bullen (norm_at_BlackKittenAssociates.com.INVALID)
Date: 09/21/04


Date: Tue, 21 Sep 2004 02:19:50 GMT

Mbear wrote:

> I'm tryint to writhe a batch script that needs a < put into the command line
> and I am not getting a succesful ru of the batch. It works fine if I type it
> directly in the command line but it is not working in a batch file.
>
> here is the line that is failing
>
> start /w c:\imail\addalias < c:\files\filename.txt
>
> When I run it form a batch file it is putting a 0 in front of the < and
> erroring out.
>
> How would I get this to wok. Thanks in advance for all the help.

If I understand correctly, you have placed the START command in a .BAT
file and when you run the .BAT you see the command echoed with a "0" in
front of the "<". It appears that you are trying to run one .BAT file as
a "sub-script" of another.

First, the "0" is _not_ a problem. This is normal when a .BAT file is
run and the statement are echoed to the screen. "<" becomes "0<" and ">"
becomes "1>". (The zero and one are the standard file descriptors for
input and output, respectively.)

The reason that your command does not work is that the input redirection
is being interpreted as part of the START command rather than part of
the command to be started. Thus the START command, if it chose to read
from standard input, would read the contents of the file
c:\files\filename.txt. The batch file being started has no standard
input redirection so it probably waits for input from the console when
it wants to read something.

To correct this, change the START statement to:
    start /w cmd /c "c:\imail\addalias < c:\files\filename.txt"

This runs the command processor and tells it to run the command on its
invocation line: c:\imail\addalias < c:\files\filename.txt
Now the redirection supplies a standard input for your .BAT file rather
than the START command.

Note that it's probably more efficient to use the CALL command rather
than the START in this situation. START with the /W option waits for the
"external" command to complete just and CALL does but it requires
starting a new instance of CMD. With CALL the statements in the .BAT
file are executed by the same instance of CMD. The equivalent CALL
statement would be
    CALL c:\imailaddalias < c:files\filename.txt
The only difference, I think, is that CALL may allow the .BAT file to
change environment variable in the calling script.

Norm

-- 
--
To reply, change domain to an adult feline.


Relevant Pages

  • Re: ie6sp1 : Repair Function Blocked - Anyone know of a fix?
    ... for command itself not to the thing it is being used to execute. ... then modifying it to do the call and append, then execute the bat file. ... Then edit dlls.bat to prefix each line with getvers and append>>versions.txt ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: commands are run alwais in root path (c: d: ...)
    ... > when i create a bat file in any folder (for example ... > So when the command in the .bat file is for example 'dir' the output is ... If the only command in the batch is DIR, then the output above does not ... Please indicate how you ran the batch. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Need DTSRUN Utility to complete before proceeding
    ... > Also would like the bat file to fail if the DTSRUN utility fail, ... discerned at the command line prodessor. ... same when run in the scheduler as when they're run on the server under ... If you write a BAT file, ...
    (microsoft.public.sqlserver.dts)
  • Re: How do I...
    ... I initiated the BAT file from the Registry without any ... trying to get the "DOS CMD.EXE" window to either run ... >> file that contained the command worked. ...
    (microsoft.public.windowsxp.setup_deployment)
  • Re: VFP 6 - problem with RUN command
    ... I think you simply need to de-bug your .bat file. ... Toos VFP to the side for ... The PAUSE command, however, functions beautifully now. ... and a CALL command to another batch file doesn't work, ...
    (microsoft.public.fox.programmer.exchange)

Loading