PSExec hangs inside of MSBuild - by gonzobent

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


10
0
Sign in
to vote
ID 327099 Comments
Status Closed Workarounds
Type Bug Repros 10
Opened 2/4/2008 10:10:25 AM
Access Restriction Public

Description

I encountered a problem trying to execute a remote command using psexec from inside of msbuild. The problem was that some commands, such as iisreset and cscript seemed to work just fine. Others, such as xcopy and mbuild would hang. Now what do I mean by hang? Msbuild would call psexec. Psexec would call xcopy. Xcopy would execute. This is the point at which it would hang. The xcopy command would be totally complete. However in the task manager on the remote machine psexecsvc would still be running. Thus the msbuild file would just sit and wait for the psexec command to complete. (I have read in some forums that this would release after 8 hours, but I don't have that kind of patience.)

It appears that when the command executed by psexec returns any more than just an error code it sometimes causes a problem. (I say sometimes because iisreset returns more than that but doesn't cause a problem for some reason.)

Things that don't work: (all of these psexec commands execute flawlessly when executed outside of msbuild from the command line.)
<Exec WorkingDirectory="$(PsToolsDirectory)"
    Command="psexec -accepteula \\$(MachineName) XCOPY $(RemoteFileLocation) $(LocalFileLocation) /s /i /y " />
The xcopy executes just fine. The first line of the returned text will be displayed by psexec/msbuild. Then psexecsvc will hang on the remote machine.

<Exec WorkingDirectory="$(PsToolsDirectory)"
    Command="psexec -accepteula \\$(MachineName) XCOPY $(RemoteFileLocation) $(LocalFileLocation) /s /i /y >$(LogFileLocation)" />
This is more of a lesson in how psexec works. This command will actually try to write the output of psexec command to a text file on the same machine that psexec executes from. This also results in psexecsvc hanging on the remote machine, and of course hanging msbuild.

Things that work:
<Exec WorkingDirectory="$(PsToolsDirectory)"
    Command="psexec -accepteula \\$(MachineName) XCOPY $(RemoteFileLocation) $(LocalFileLocation) /s /i /y /q" />
Here psexec executes xcopy directly. In this example the text output is totally swallowed using the /q flag. The tradeoff here is that if xcopy exits with an unsuccessful error code, then psexec returns that to msbuild and msbuild reports an error and stops running. Or if you prefer you can set ContinueOnError="true". In that case msbuild would continue, but would report a warning.

The trouble with this solution is that we don't get much feedback on what went wrong.

<Exec WorkingDirectory="$(PsToolsDirectory)"
    Command="psexec -accepteula \\$(MachineName) cmd.exe /c &quot;XCOPY $(RemoteFileLocation) $(LocalFileLocation) /s /i /y >$(LogFileLocation)&quot;" />
In this case psexec opens a new command shell on the local machine using cmd. This command shell then executes the xcopy command and the output is saved to a text file. If xcopy has an error code it will bubble back up to msbuild. There are still some messages that get lost in this process, but this is the best workaround that I have been able to assemble.

If you have any other ideas or insights, I would sure like to hear them.
Sign in to post a comment.
Posted by Fabian Schmied on 12/2/2013 at 1:14 AM
Follow-up issue for MSBuild 4: https://connect.microsoft.com/VisualStudio/feedback/details/810440/psexec-hangs-inside-of-msbuild-with-msbuild-4
Posted by Fabian Schmied on 7/15/2013 at 1:40 AM
Should be reopened, it still reproduces with MSBuild 4 (4.0.30319.17929).
Posted by Christian Schnidrig on 9/23/2008 at 12:53 AM
found the best workaround for this problem:

don't use psexec - use remcom
-> http://sourceforge.net/projects/rce/

- it's an open source project who's inspired by psexec
- usefull for the gacutil-remote-thing
- workx! :)
Posted by Christian Schnidrig on 9/17/2008 at 2:33 PM
pls bring a fix for 2005/2008!

Workaround:
1) On the remote desktop make a batch file with the commant(s) you want to execute on the remote machine
2) psexec "\\remoteServer" "c:\temp\remoteBatch.bat"
Posted by odanvin on 9/1/2008 at 2:41 AM
Where can we download and test MSBuild 4.0 Beta?
Posted by odanvin on 9/1/2008 at 2:40 AM
We can we donload and test MSBuild 4.0 Beta?
Posted by Microsoft on 8/28/2008 at 7:02 PM
If you still see the issue in MSBuild 4.0 Beta, please do reactivate and/or email msbuild@microsoft.com.
Dan
Posted by Microsoft on 8/28/2008 at 7:02 PM
If you still see the issue in MSBuild 4.0 Beta, please do reactivate and/or email msbuild@microsoft.com.
Dan
Posted by Microsoft on 8/28/2008 at 7:01 PM
This issue should be fixed in the next version.
Thanks
Dan
Posted by Melanie Culver on 6/18/2008 at 6:09 AM
is there a solution yet?
Posted by Microsoft on 2/4/2008 at 10:56 PM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 2/4/2008 at 10:24 PM
Thank you for your feedback. We are currently investigating. The investigation process normally takes 7-14 days. If this issue is urgent, please contact support directly (see http://support.microsoft.com).

If at any time your issue is closed unsatisfactorily, you may edit your issue via Connect and change the status to “Active.”

Thank you,
Visual Studio Product Team