0

I'm running a bat file located on a remote server. The command is: wmic /node:[server name] process call create "cmd.exe /c [bat file location]. I would like the command to wait until the batch file execution completing. In other words: the command is part of Jenkins (Hudson) job, and the next step after the window batch command starting before the batch file tasks completed. I would like the next step to be executed just after the batch file execution completing. * The batch file task (content) is restoring of a DB.

1 Answer 1

0

Next commented code snippet could do the job. Unfortunately, I can test it only on local node.

@ECHO OFF SETLOCAL EnableExtensions DisableDelayedExpansion set "_toRun=cmd.exe /C pause" change to meet your circumstances set "_where=." sorry testing merely local computer set "_toGet=ProcessId ReturnValue" set "_ProcessId=" set "_ReturnValue=" rem %%G loop to get raw return values from `create` like next two lines rem ProcessId = 6476; rem ReturnValue = 0; for /F "tokens=*" %%G in (' wmic /node:"%_where%" process call create "%_toRun%" ^| findstr "%_toGet%" ') do ( rem %%g loop to assign values to variables `_ProcessId` and `_ReturnValue` for /F "tokens=1,2 delims=;= " %%g in ("%%~G") do ( set "_%%~g=%%~h" ) ) if NOT "%_ReturnValue%"=="0" ( echo %_toRun% failed, Return Value %_ReturnValue% goto :notest ) echo process %_toRun% runs as %_ProcessId% rem build WQL query set "_query=ProcessId = %_ProcessId% and CommandLine = '%_toRun:\=\\%'" rem loop while queried process runs :test set "_CommandLine=" for /F %%G in (' wmic /node:"%_where%" process where "%_query%" get CommandLine /value ^| findstr "=" ') do set "_%%~G" if not defined _CommandLine goto :notest set _Comman >NUL timeout /T 5 /NOBREAK goto :test :notest 

Resources (required reading, incomplete):

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.