简体   繁体   中英

Can't run a command in a batch file while in command prompt it executes

Been stuck on this for a while now, I've tried finding the answer on this and similar forums but nothing worked.

I got this command:

 FOR /F "tokens=3 skip=1" %i IN (C:\logoff\query.txt) DO logoff %i /server:192.168.0.231

Where basically it takes number from query.txt file and it loggs off the user from server by his session id number.

It works if I execute command in a command prompt, but I can't seems to get it working on a batch. I've tried doubling the percentage signs, like someone suggested in forums - nothing.

I assume to confirm the command should work on batch it should execute using "Run...", it doesn't though..

Is the problem that the command starts with FOR or what is the case? I give up..

The for replaceable parameters (the "variable" containing the current value of the iteration) uses the %x syntax. But inside a batch file, the percent sign needs to be escaped and the syntax is %%x (see for /? ).

FOR /F "tokens=3 skip=1" %%i IN (C:\logoff\query.txt) DO logoff %%i /server:192.168.0.231
                         ^^                                     ^^

Try this:

for /F "usebackq tokens=3 skip=1 delims=|" %%i in ("C:\logoff\query.txt") do logoff %%i /server:192.168.0.231

I thing you problem is like @MC ND said and you forget to use delims .

in you query.txt must something like this:

1|1|111
2|2|222
3|3|333

output:

logoff 222 /server:192.168.0.231
logoff 333 /server:192.168.0.231

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM