Run a batch using file as parameter out of current directory

June 3, 2013 at 17:56:17
Specs: Windows 7
I am trying to run a simple bat directly from the command prompt. bat file takes as parameter a file that does not belong to my current directory. Please look at the error I have got each time and I don't understand why since echoing "%~f1" returns "D:\WorkpaceDEV\opt\ABC\IJS_002.TXT" successfully and my text file is absolutely present into the folder D:\WorkpaceDEV\opt\ABC".

That would seem odd to me!

C:\Users\bob\Desktop\DEV\Workspace>run.bat "D:\WorkpaceDEV\opt\ABC\IJS_002.TXT"
La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.

Here's is the bat

@ echo off
echo "%~f1"
findstr /r "I.*=" "%~f1" >outer.TXT

Thank you very much to open my eyes on this issue

See More: Run a batch using file as parameter out of current directory

Report •

June 3, 2013 at 18:43:42
Sorry for "non-help", but I could not get this error to occur (win-xp and win-7 both). Only thing I can think is, check your batch for non-display characters: EDIT /70 RUN.BAT and look for any "suspicious characters" lurking about. NOTEPAD may not show them.

Report •

June 3, 2013 at 21:35:53
I'm lost. What is this:


M2 Golden-Triangle

Report •

June 3, 2013 at 23:42:36
"I.*=" is a matching rule. No problem about that. In fact when my file is in the folder where the bat is, I get what I want to, all is fine. But when the same file is in another directory as the current directory, this issue occurs. Moreover I have no spaces, no special character into my path. As for me, it seems to me very strange!
I'm on seven 32, i don't know if it may help.
Nbrane have said just before that he doesn't meet that, I don't know why I got it.
Thanks for your help

Report •

Related Solutions

June 4, 2013 at 07:32:23
I would assume it doesn't like the output redirector, or some extra cruft snook into the file. Keep echo on and remove the redirection. If the file looks clean and it runs, reintroduce the redirection. If it fails again, make sure you have write/create/modify access to the current directory.

How To Ask Questions The Smart Way

Report •

June 4, 2013 at 09:08:27
Here try this:
@echo off
echo "%~f1"
set dir=%cd%
findstr /r "I.*=" "%~f1" > %dir%\outer.TXT

Report •

Ask Question