For loop problem again

March 17, 2009 at 04:56:54
Specs: Windows XP
Dear friends,

This is a continuation of my previous first post.
Please click here

I have another problem which i can't understand. The following batch script gives this error: The syntax of the command is incorrect.

It works fine till this line
echo %speechDirectory%.

Kindly provide your valuable help.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: HANDLE IMPROPER COMMAND LINE ARGUMENTS

If %1=="" (
echo Provide input file name and the output directory
exit /b
)

If %2=="" (
echo Provide input file name and the output directory
exit /b
)

set input=%1

:: HANDLE FILE NOT FOUND CONDITION -- START
if not exist %input% (
echo File Not Found or Does not exist.
exit /b
)
:: HANDLE FILE NOT FOUND CONDITION -- END

:: PROCESS FILE FOR PHRASE GENERATION -- START

if exist %input% goto processBatch


: processBatch
set executableFile="C:\Program Files\ScanSoft\RealSpeak 4.0\standard.exe"
set language="Indian English"
set speechDirectory="C:\Program Files\ScanSoft\RealSpeak 4.0\speech"
echo %executableFile%
echo %language%
echo %speechDirectory%
for /F "tokens=1,2* delims=|" %%i in (%input%) do (
echo "INSIDE FOR LOOP"
echo %%j > %2\Output.txt
echo "GOTO INNER FOR LOOP"
for /f "tokens=*" %%a in (%2) do (
echo INSIDE INNER FOR LOOP
set var=%%~a
echo ------------------->> %var%
set output="%var%\Output.txt"
echo Output: %output%
call %executableFile% %language% Sangeeta %speechDirectory% %output%
set pcmFile=%%i.pcm
rename "standard.pcm" !pcmFile!
move !pcmfile! %2
)
echo DONE
)
echo Completed generating '.pcm' files in this directory: %2
exit /b

:: PROCESS FILE FOR PHRASE GENERATION -- END

Thanks,
Vijay


See More: For loop problem again

Report •


#1
March 17, 2009 at 11:58:44
for /F "tokens=1,2* delims=|" %%i in (%input%) do (

Avoid using the bar '|' symbol; it has a special significance to Command Prompt.

ALSO: Avoid nested FOR loops; it can only end in pain and suffering. Yours, specifically.


Report •

#2
March 17, 2009 at 23:51:25
In the interest of pain and suffering:


You can specify | as a delimiter so long as you escape it with a ^carat.

for /F "tokens=1,2* delims=^|" %%i in (%input%) do (

As for nested for loop I for one often end up counting - 1,2,3,4,5,6 opening brackets - 1,2,3,4,5 closing brackets - AHA! What fun it is....


Report •

#3
March 18, 2009 at 23:06:22
Dear friends,

Thanks for the reply. Sorry for the delayed reply as i was not feeling well.
A small doubt.
If i give two input parameters at the command line like this:
MyBat.bat C:\Program Files\My Folder\Name List.txt
MyBat.bat C:\Program Files\My Folder\Output Folder

How to tell the batch script to take it as "C:\Program Files\..."

I gave the input without quotes
and inside the batch script i set like this:

set input="%1"
set output="%2"
But, when i echo input it prints only "C:\Program".

What could be the problem?

Kindly provide your valuable help!

Thanks,
Vijay



Report •

Related Solutions

#4
March 18, 2009 at 23:31:40
Use quotes.
MyBat.bat "C:\Program Files\My Folder\Name List.txt"
MyBat.bat "C:\Program Files\My Folder\Output Folder"


Report •


Ask Question