"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