Getting the output of a batchfile to Powershell


greetings. have list of batchfiles triggers powershell script, throw error message when different errors encountered in execution. 

in end of batchfile, have included:
if %errorlevel% neq 0 (echo error in previous command & exit /b %errorlevel%)
and works fine in itself. 

however due requirements need use new separate batchfile triggers powershell, in turn lauch batchfiles mentioned earlier. 

in new powershel, have included: 
$process = start-process $batchfile.fullname -argumentlist $argumentlist -passthru -wait 
and able $process.exitcode. output or error message raised first batchfile instead. 

any advice?

hi bdrc,

if want to capture output of batch file, please try run batch file like:

d:\test.bat argu1 argu2

and cmdlet start-process will start a process with the batch file.

for more detailed information, please refer article:

how execute .bat file within powershell job

if there else regarding issue, please feel free post back.

best regards,

anna wang



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

RDS 2012 r2 collections show black screen and then close