Psexec output in %%i

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Psexec output in %%i

Post by MigrationUser »

18 Sep 2013 08:21
dima4ka

Hi all,

i need help for my cmd.

Code: Select all

for /f "tokens=1,* delims= " %%i IN (c:\tmp\version.txt) do (
echo %%i>>c:\tmp\version_output.txt
c:\windows\system32\psexec.exe \\%%i cmd /c ver>>c:\tmp\version_output.txt
)
what i need is, that i can catch the output of psexec in a variable (%%version)

Code: Select all

for /f "tokens=1,* delims= " %%i IN (c:\tmp\version.txt) do (
echo %%i>>c:\tmp\version_output.txt
c:\windows\system32\psexec.exe \\%%i cmd /c ver>>%%version
Echo PC %%i have version: %%version
)
thanks a lot

----------------------------

#2 19 Sep 2013 10:21

bluesxman


For the code you've shown, you don't really need an actual variable. Something like this should do the trick (I've included what I think you need and also what you asked for, so take your pick):

Code: Select all

for /f "tokens=1,* delims= " %%i IN (c:\tmp\version.txt) do (
echo %%i>>c:\tmp\version_output.txt
for /f "usebackq tokens=*" %%O in (`c:\windows\system32\psexec.exe \\%%i cmd /c ver 2^>nul`) do (
  echo:NoVariableNeeded -- PC %%i have version: %%O
  set version=%%O
  call echo:PC %%i have version:%%version%%
))
cmd | *sh | ruby | chef

----------------------------

#3 19 Sep 2013 13:12
dima4ka


Great.

THX.

Question:
what means 2^>nul?

Last edited by dima4ka (19 Sep 2013 13:40)

----------------------------

#4 19 Sep 2013 15:11
Giacomo
dima4ka wrote:

what means 2^>nul?
Redirection
ss64.com wrote:

command 2> filename Redirect any error message into a file
Syntax : Escape Characters, Delimiters and Quotes
^ is to escape the >.

NUL
ss64.com wrote:

The null device is a special file that discards all data written to it, but reports that the write operation succeeded.

It is often used to hide the output (or error output) of a command
Last edited by Giacomo (20 Sep 2013 08:22)

----------------------------

#5 20 Sep 2013 03:38
foxidrive
Giacomo wrote:

^ is to escape the >.
Yes, if you want to echo it (or in a for command tail)

I, for one, am not sure what your post intended to say.

Last edited by foxidrive (20 Sep 2013 03:38)

----------------------------

#6 20 Sep 2013 08:26
Giacomo
foxidrive wrote:

I, for one, am not sure what your post intended to say.
I edited my previous post, now it should be understandable, sorry guys
Post Reply