badly processed arguments(directories)

June 12, 2009 at 05:54:03
Specs: Windows XP
If you could help me it would be highly appreciated since I should use the result to continue my project i've to present wednesday!
Furthermore, I've no knowlegde about .bat-files at all...


I'm calling the programm treetagger ( automatically in a perlscript via the corresponding .bat-files (corresponding to the language of the text: example: tag-english.bat) distributed togheter with treetagger!
The arguments of these .bat-files are directories. If the directories passed as arguement do not include spaces, it works perfectly fine. However if they do include spaces - what is crucial in my project -, there appears an error-message saying that the second word of the argument "cannot be processed at this place".

These .bat files (example tag-english.bat at the end) do not correctly process arguments with spaces.
-How do I solve that?

PRECISE LOCALISATION OF THE PROBLEM (simple case: assume only one argument %1):
In the .bat-files, in the command:

perl %CMD%\ -e -a %LIB%\english-abbreviations %1 | %BIN%\tree-tagger %TAGOPT%

=> There is a SYNTAXICAL ERROR in this line when the argument %1 contains spaces (The perl-script is never started, I tested.).

I tried many things refering among others to
but since I have no background about windows bat-files it's just try an error...
By the way I use Windows XP, but the solution should work for any windows if possible!:)

Any help would be highly appreciated!!!!

Best regards,


example tag-english.bat:

@echo off

set TAGDIR=C:\Programme\TreeTagger

set BIN=%TAGDIR%\bin
set CMD=%TAGDIR%\cmd
set LIB=%TAGDIR%\lib
set TAGOPT=%LIB%\english.par -token -lemma -sgml -no-unknown -cap-heuristics -hyphen-heuristics

if "%2"=="" goto label1
perl %CMD%\ -e -a %LIB%\english-abbreviations %1 | %BIN%\tree-tagger %TAGOPT% > %2
goto end

if "%1"=="" goto label2
perl %CMD%\ -e -a %LIB%\english-abbreviations %1 | %BIN%\tree-tagger %TAGOPT%
goto end

echo Usage: tag-english file {file}


See More: badly processed arguments(directories)

Report •

June 12, 2009 at 07:08:13
Arguments on command line with spaces must be embraced by double quotes ("")

mybatch "C:\My Dir\" "Second Parameter"

and in the script body you have to refer to the arguments (with blanks) as

"%~1" or "%~2"

In the case of directories or file names in the script body you can code as alternative

%~s1 and so on (%~s2)

transforming a Windows lenght path name into the classic 8.3 DOS format.

I hope you can understand my hint.

Report •

June 12, 2009 at 08:34:13
if you have Perl, why don't you do everything with Perl?

Report •

June 12, 2009 at 10:03:53
thank you IVO!
It workes using

"%~1" or "%~2"

to refere to the arguments (and of course embracing the arguments with spaces using double quotes when calling the batch).

So concretely, I just replaced %1 and %2 everywhere in the batch with "%~1" and "%~2"..

So thank you very much for the immediate help!

best regards, sam

PS: @ghostdog: i didn't do it in perl because then i would have had to find out the directory where the user has treetagger installed... in this apparantly automatically generated batchs at installing time of treetagger there isnt this problem... Furthermore theese batchs works like option-files for the user for every language: they allow the user to choose specific options or simply use another tokenizer depending on the language etc. So i now i will just write the guy who distributed treetagger to correct his batch-files in his distribution and... ...problem solved:)

Report •

Related Solutions

Ask Question