Reputation: 1159
After several searches in INTERNET, It seems that it is obviously not possible to run a batch with a file whose path is not the same as the bat file (located at the current directory). So can you tell me if there is a workaround for this issue, without copying this file to the current directory?
For further information, please look at below the error I have got each time I ran the bat with a parameter out of my current directory. 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".
C:\Users\bob\Desktop\DEV\Workspace>
C:\Users\bob\Desktop\DEV\Workspace>run.bat "D:\WorkpaceDEV\opt\ABC\IJS_002.TXT"
"D:\WorkpaceDEV\opt\ABC\IJS_002.TXT"
La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.
Here's is my origin bat file
@ echo off
echo "%~f1"
findstr /r "I.*=" "%~f1" >outer.TXT
it seems to me that: the error message I have gotten is related to a configuration problem, But I am not sure! If it could help, I am on Seven 32. Please Let me also know if you encounter this problem on your side. If it is the case, perhaps we could conclude that it is a Bug from Microsoft? I'm really blocked and I look forward getting from you. Thank you very much to open my eyes on this issue
Upvotes: 2
Views: 404
Reputation: 1159
echo %ComSpec% was not showed anything at prompt command . I don't know why. Therefore set it to "C:\Windows\system32\cmd.exe" has solved the issue.
Thank you all for your investigation.
Upvotes: 0
Reputation: 67216
Well, the use of %~f1
does NOT guarantee that the file exists! If the parameter given to the Batch file includes the full path, then %~f1
just return the same information and does not check for the existence of the file.
I suggest you to test the Batch file below:
@ echo off
echo "%~f1"
if exist "%~f1" (
findstr /r "I.*=" "%~f1" >outer.TXT
) else (
echo File does NOT exist!
)
Upvotes: 3