• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

CMD commands vs .bat commands

Nathan

n00b
Joined
Apr 23, 2009
Messages
41
Hello,

I am not exaclty sure if this is the right place to be posting this but it may be considered OS b/c it is windows specific?

Anyways here is the situation. I would like to run a .bat file to run a program through the command line. Here is the code I would like to run from the cmd.

Code:
for /R %i IN (.) do "C:\Program Files\WinRAR\Rar.exe" x "%i/*.rar"

Since it is in a .bat I can copy the bat file to the directory and then run the .bat

Here is the problem, when I run it in a .bat it just shows up and disappears. (it doesnt even look like it gets past the command) but the cmd needs to stay open to run the command.

I have tried "pause" and I have also tried to run a "cmd /k" as:
Code:
cmd /k 
for /R %i IN (.) do "C:\Program Files\WinRAR\Rar.exe" x "%i/*.rar"
and
Code:
for /R %i IN (.) do "C:\Program Files\WinRAR\Rar.exe" x "%i/*.rar" 
cmd /k

and finally:
Code:
cmd /k for /R %i IN (.) do "C:\Program Files\WinRAR\Rar.exe" x "%i/*.rar"

None of which worked.

I then tried to run a pause after an echo after the last command ^

Here is exactly what the .bat says:
Code:
cmd /k for /R %i IN (.) do "C:\Program Files\WinRAR\Rar.exe" x "%i/*.rar" 
echo test
pause
And here is the output.
Code:
C:\Users\Toshiba\Desktop\testing>cmd /k for /R[COLOR="Lime"] \Program Files\WinRAR\Rar.exe" x
"i/*.rar"[/COLOR]
[COLOR="Lime"]Files\WinRAR\Rar.exe" x "i/*.rar"  was unexpected at this time.[/COLOR]

C:\Users\Toshiba\Desktop\testing>echo test
test

C:\Users\Toshiba\Desktop\testing>pause
Press any key to continue . . .

It seems as though the bat isnt importing the exact line into the cmd window. Any Ideas?
 
You have to run .bat files as admin for them to work correctly in Vista/Win7. Are you doing that?
 
Try escaping the percent sign using a double percent sign:

for /R %%i IN (.) do "C:\Program Files\WinRAR\Rar.exe" x "%%i/*.rar"
 
Looks like you're trying to archive a large amount of files?

I use the following to xcopy them to a different drive, then I image the drive.

for /f "delims=" %%i in (archives.txt) do echo F|xcopy "K:\%%i" "F:\Archive\%%i" /c /i /z /y

It looks through archives.txt and runs the command for each entry. I too use the %%i
 
Thank you it worked!!!

Now because I am a person of knowledge, Why is this the case? do .bet files ignore "%" but "%%" is read as "%"
 
As the % is an escape character, you need to escape it in order to have a literal % (that is used to expand the '%i' variable).
 
As the % is an escape character, you need to escape it in order to have a literal % (that is used to expand the '%i' variable).
Co-signed.

Nathan: In general, you don't need admin rights to run a cmd file. However, you do need admin rights if you are going to touch a resource/perform an operation that requires admin rights.
 
Back
Top