Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Run PsExec non-sequentially in a batch file

Reply
Thread Tools Display Modes

Run PsExec non-sequentially in a batch file

 
 
M
Guest
Posts: n/a

 
      03-25-2010
Hello:

Is it possible to run PsExec non-sequentially in a batch file? The example
below does not work. I get the output txt files, but they're blank. If I
remove "start" from each line, then everything works fine, but then the
commands run sequentially, so if I have 30 lines, I'd have to wait several
minutes for the entire batch file to complete. Note that I'm only using
ipconfig as a simple example.

Start C:\PsExec\psexec \\Server1 ipconfig /all > c:\temp\Server1.txt
Start C:\PsExec\psexec \\Server2 ipconfig /all > c:\temp\Server2.txt
Start C:\PsExec\psexec \\Server3 ipconfig /all > c:\temp\Server3.txt
Pause

Thank you.
--
Regards,
M
MCTS, MCSA
http://SysAdmin-E.com


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-25-2010


"M" <> wrote in message
news:...
> Hello:
>
> Is it possible to run PsExec non-sequentially in a batch file? The example
> below does not work. I get the output txt files, but they're blank. If I
> remove "start" from each line, then everything works fine, but then the
> commands run sequentially, so if I have 30 lines, I'd have to wait several
> minutes for the entire batch file to complete. Note that I'm only using
> ipconfig as a simple example.
>
> Start C:\PsExec\psexec \\Server1 ipconfig /all > c:\temp\Server1.txt
> Start C:\PsExec\psexec \\Server2 ipconfig /all > c:\temp\Server2.txt
> Start C:\PsExec\psexec \\Server3 ipconfig /all > c:\temp\Server3.txt
> Pause
>
> Thank you.
> --
> Regards,
> M
> MCTS, MCSA
> http://SysAdmin-E.com


This is tricky stuff. You probably have to do it as below. Make sure to
store the code in the referenced batch file (c:\Tools\PSBatch.bat) and to
invoke it without any parameter.

@echo off
goto Label%1

:Label
set batch=c:\Tools\PSBatch.bat
Start /b %batch% 1
Start /b %batch% 2
Start /b %batch% 3
exit

:Label1
if exist c:\Server1.txt del c:\Server1.txt
cmd.exe /c psexec \\Server1 ipconfig /all > c:\Server1.txt
exit

:Label2
if exist c:\Server2.txt del c:\Server2.txt
cmd.exe /c psexec \\Server2 ipconfig /all > c:\Server2.txt
exit

:Label2
if exist c:\Server3.txt del c:\Server3.txt
cmd.exe /c psexec \\Server3 ipconfig /all > c:\Server3.txt
exit


 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      03-25-2010



"Pegasus [MVP]" <> wrote in message
news:...
>
>
> "M" <> wrote in message
> news:...
>> Hello:
>>
>> Is it possible to run PsExec non-sequentially in a batch file? The
>> example below does not work. I get the output txt files, but they're
>> blank. If I remove "start" from each line, then everything works fine,
>> but then the commands run sequentially, so if I have 30 lines, I'd have
>> to wait several minutes for the entire batch file to complete. Note that
>> I'm only using ipconfig as a simple example.
>>
>> Start C:\PsExec\psexec \\Server1 ipconfig /all > c:\temp\Server1.txt
>> Start C:\PsExec\psexec \\Server2 ipconfig /all > c:\temp\Server2.txt
>> Start C:\PsExec\psexec \\Server3 ipconfig /all > c:\temp\Server3.txt
>> Pause
>>
>> Thank you.
>> --
>> Regards,
>> M
>> MCTS, MCSA
>> http://SysAdmin-E.com

>
> This is tricky stuff. You probably have to do it as below. Make sure to
> store the code in the referenced batch file (c:\Tools\PSBatch.bat) and to
> invoke it without any parameter.
>
> @echo off
> goto Label%1
>
> :Label
> set batch=c:\Tools\PSBatch.bat
> Start /b %batch% 1
> Start /b %batch% 2
> Start /b %batch% 3
> exit
>
> :Label1
> if exist c:\Server1.txt del c:\Server1.txt
> cmd.exe /c psexec \\Server1 ipconfig /all > c:\Server1.txt
> exit
>
> :Label2
> if exist c:\Server2.txt del c:\Server2.txt
> cmd.exe /c psexec \\Server2 ipconfig /all > c:\Server2.txt
> exit
>
> :Label2
> if exist c:\Server3.txt del c:\Server3.txt
> cmd.exe /c psexec \\Server3 ipconfig /all > c:\Server3.txt
> exit


What might not be clear in the above solution is an explanation of the
phenomenon.

The start command runs the command it is given in a separate process. The
start command itself produces no output, which is why the .txt files are
empty. If you run the start commands without redirecting the output, you
should see that, indeed, no output is done in the console window. If the
command being started opens another console window (as should be the case
for psexec), that is where the output is displayed.

The trick Pegasus provided is to get start to run a controlling batch file
in which the batch file you want the output from is run with redirection. I
don't have an environment in which to test using psexec, but I was able to
use start to run a batch file and capture its output. Here is the syntax:

start cmd.exe /c z.bat ^>z.txt

If this were to work with psexec it might just be a matter of changing this:

Start C:\PsExec\psexec \\Server1 ipconfig /all > c:\temp\Server1.txt

to this:

Start cmd.exe /c C:\PsExec\psexec \\Server1 ipconfig /all ^>
c:\temp\Server1.txt

/Al


 
Reply With Quote
 
M
Guest
Posts: n/a

 
      03-26-2010
Thanks everyone for the replies. I ended up not needing to do anything of
this since plans changed and I won't need to use PsExec now. I will keep
everything for reference and will test it out when I have a chance.

--
Regards,
M
MCTS, MCSA
http://SysAdmin-E.com
"Al Dunbar" <> wrote in message
news:7798D77F-7CF6-4CEB-B15A-...
>
>
> "Pegasus [MVP]" <> wrote in message
> news:...
>>
>>
>> "M" <> wrote in message
>> news:...
>>> Hello:
>>>
>>> Is it possible to run PsExec non-sequentially in a batch file? The
>>> example below does not work. I get the output txt files, but they're
>>> blank. If I remove "start" from each line, then everything works fine,
>>> but then the commands run sequentially, so if I have 30 lines, I'd have
>>> to wait several minutes for the entire batch file to complete. Note that
>>> I'm only using ipconfig as a simple example.
>>>
>>> Start C:\PsExec\psexec \\Server1 ipconfig /all > c:\temp\Server1.txt
>>> Start C:\PsExec\psexec \\Server2 ipconfig /all > c:\temp\Server2.txt
>>> Start C:\PsExec\psexec \\Server3 ipconfig /all > c:\temp\Server3.txt
>>> Pause
>>>
>>> Thank you.
>>> --
>>> Regards,
>>> M
>>> MCTS, MCSA
>>> http://SysAdmin-E.com

>>
>> This is tricky stuff. You probably have to do it as below. Make sure to
>> store the code in the referenced batch file (c:\Tools\PSBatch.bat) and to
>> invoke it without any parameter.
>>
>> @echo off
>> goto Label%1
>>
>> :Label
>> set batch=c:\Tools\PSBatch.bat
>> Start /b %batch% 1
>> Start /b %batch% 2
>> Start /b %batch% 3
>> exit
>>
>> :Label1
>> if exist c:\Server1.txt del c:\Server1.txt
>> cmd.exe /c psexec \\Server1 ipconfig /all > c:\Server1.txt
>> exit
>>
>> :Label2
>> if exist c:\Server2.txt del c:\Server2.txt
>> cmd.exe /c psexec \\Server2 ipconfig /all > c:\Server2.txt
>> exit
>>
>> :Label2
>> if exist c:\Server3.txt del c:\Server3.txt
>> cmd.exe /c psexec \\Server3 ipconfig /all > c:\Server3.txt
>> exit

>
> What might not be clear in the above solution is an explanation of the
> phenomenon.
>
> The start command runs the command it is given in a separate process. The
> start command itself produces no output, which is why the .txt files are
> empty. If you run the start commands without redirecting the output, you
> should see that, indeed, no output is done in the console window. If the
> command being started opens another console window (as should be the case
> for psexec), that is where the output is displayed.
>
> The trick Pegasus provided is to get start to run a controlling batch file
> in which the batch file you want the output from is run with redirection.
> I don't have an environment in which to test using psexec, but I was able
> to use start to run a batch file and capture its output. Here is the
> syntax:
>
> start cmd.exe /c z.bat ^>z.txt
>
> If this were to work with psexec it might just be a matter of changing
> this:
>
> Start C:\PsExec\psexec \\Server1 ipconfig /all >
> c:\temp\Server1.txt
>
> to this:
>
> Start cmd.exe /c C:\PsExec\psexec \\Server1 ipconfig /all ^>
> c:\temp\Server1.txt
>
> /Al
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add-Ons "run without permission." OREALLY Internet Explorer 2 01-19-2010 06:09 AM
Leftover folders after Microsoft Update mme000 \(add @yahoo.it to my nick\) Windows Update 21 12-26-2009 10:11 PM
Server 2003 update problem kc66 Windows Update 7 12-22-2009 04:09 PM
error code 0x8024D007 jenny Windows Update 10 11-23-2009 05:48 PM
File not in Explorer but opens anyhow Toyman Windows Vista File Management 5 07-24-2007 11:06 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59