WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DOS

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Redirection Symbol Not Working

Keywords:	 redirect output redirection /c command.com Pipe > data to file

You can't use a Run command like:

	Run("mem.exe", "> mem.txt")

Windows limitation. Instead, use:

	Run(Environment("COMSPEC"), "/c mem >mem.txt")
Note:

You can get a list of the inventory of a hard drive and send it to a text file by using the following line:

	RunWait(Environment("COMSPEC"),"/c dir c:\ /s > c:\hd.txt") 

Hd.txt is the file the info is being sent to.


Question:

I am trying to run an .EXE for a totally different application. THe syntax is what I got from the vendor documentation. I can run it fine from a DOS window but get this error when trying to run the batch file from Winbatch:
Error 3068: function syntax, illegal delimiter found.
I have no control over the < required for this .EXE. as follows
"ppadmtool.exe" < enable.txt

Answer:

In that case....
DirChange("C:\Desired Start-in Directory")
cmd=Environment("COMSPEC")
RunWait(cmd,"/c ppadmtool.exe <enable.txt")
Note. No space between < and enable.txt

Question:

I am attempting to run a DOS command using the RunWait command with the generic "ANYCMD.BAT" technique. This has worked fine for me in the past, but in this case seems to be having a problem. The command I am trying to execute is as follows:
	RunWait("ANYCMD.BAT", "net use y: > c:\test.txt")
where ANYCMD.BAT contains:
	%1 %2 %3 %4 %5 %6 %7 %8 %9
I have noticed that the redirection character ('>') seems to be the problem here... On WinNT 3.51 the above does not work at all, and on Win95 ANYCMD.BAT only receives the 1st 3 parameters (ie. net use y:) and drops the rest. Any ideas???

Answer:

It is not Windows that cannot do redirection, it is the nature of Dos batch files to not be able to do redirection, due to the nature of how Dos batch is incorporated within the Dos shell.

Two solutions. Take your choice:

  1. comspec=Environment("COMSPEC") RunWait(comspec,"/c net use y: > c:\test.txt")
  2. OR

  3. RunWait("ANYCMD2.bat", "c:\test.txt net use y:")
where a simple ANYCMD2.BAT contains something like (or a more detailed BAT file might be necessary, as in the example following this one):
	%2 %3 %4 %5 %6 %7 %8 %9 > %1 

You might need to change your ANYCMD.BAT to something like the following:

	@echo off
	echo %1 %2 %3 %4 %5 %6 %7 %8 %9|find "}" >nul
	if errorlevel 1 goto NoRedir
	:IsRedir
	If [%1]==[}] Exit :: impossible
	If [%2]==[}] Goto Do2
	If [%3]==[}] Goto Do3
	If [%4]==[}] Goto Do4
	If [%5]==[}] Goto Do5
	If [%6]==[}] Goto Do6
	If [%7]==[}] Goto Do7
	If [%8]==[}] Goto Do8
	If [%9]==[}] Exit :: impossible
	Exit :: should not happen
	:Do2
	%1 > %3
	Exit
	:Do3
	%1 %2> %4
	Exit
	:Do4
	%1 %2 %3> %5
	Exit
	:Do5
	%1 %2 %3 %4> %6
	Exit
	:Do6
	%1 %2 %3 %4 %5> %7
	Exit
	:Do7
	%1 %2 %3 %4 %5 %6> %8
	Exit
	:Do8
	%1 %2 %3 %4 %5 %6 %7> %9
	Exit

	:NoRedir
	%1 %2 %3 %4 %5 %6 %7 %8 %9
	Exit
I've given this initial tests and I believe it should work either as is or with minimal tweaking. One thing you MUST do is substitute "}" for ">" when you call the batch file, and the batch file changes it back to ">".

Also, while in Dos you do not need spaces before or after the ">", you must treat "}" as a separate word for this batch file to work.

eg:

	RunWait("ANYCMD.BAT","one two three } five")

Article ID:   W12898
Filename:   Slash C and Redirection Symbol Not Working.txt
File Created: 2013:02:12:09:56:08
Last Updated: 2013:02:12:09:56:08