简体   繁体   English

在 Visual Studio 生成后事件中运行交互式批处理

[英]Run interactive batch in Visual Studio post build events

I have a program written in vb.net.我有一个用 vb.net 编写的程序。 After I build, I want to launch an interactive batch file that executes a psexec command remotely.构建后,我想启动一个交互式批处理文件,远程执行 psexec 命令。 How can I do that?我怎样才能做到这一点? this is my post build event:这是我的后期构建活动:

call "$(ProjectDir)ExecOnGw.bat"

And this is my batch that if it runs in a normal command prompt, execution is ok.这是我的批处理,如果它在正常的命令提示符下运行,执行是可以的。

c:\Sysinternal\psexec.exe \\gateway "C:\Remotepath\mybatch.bat" -u mydomain\myuser -p ******
pause

This batch calls another batch on a remote machine that does something, then if I want to exit, I have to press a "q" and "Enter".这个批处理调用远程机器上的另一个批处理,然后如果我想退出,我必须按“q”和“Enter”。 In a normal command prompt, it works fine.在正常的命令提示符下,它工作正常。 But in a Visual Studio post build event it goes down.但是在 Visual Studio 后期构建事件中它会下降。 Help me!帮我!

I've done this before using the start command.我在使用 start 命令之前已经这样做了。 I created a simple pause.bat file to demonstrate:我创建了一个简单的 pause.bat 文件来演示:

    @echo off
    pause Press Any Key
    exit

If I put this in the post build event, I see a console that just closes.如果我把它放在构建后的事件中,我会看到一个刚刚关闭的控制台。

call pause.bat

If I use this instead, I get a second console window that takes my input before closing.如果我改用它,我会得到第二个控制台窗口,它在关闭之前接受我的输入。

start "My Process" /D c:\batch /WAIT pause.bat

Here is info about our technical development environment :以下是有关我们技术开发环境的信息:

  • Microsoft Visual Studio Enterprise 2019微软 Visual Studio 企业版 2019

    .NET Core 3.1 .NET 核心 3.1

Just to add to @dsway good answer, I used Visual Studio 2019's macros so that I could keep the directory path as relative:只是为了添加到@dsway 的好答案,我使用了 Visual Studio 2019 的宏,以便我可以将目录路径保持为相对:

start "My Process" /D "$(SolutionDir)Scripts" /WAIT blahblah.bat开始“我的进程”/D“$(SolutionDir)Scripts”/WAIT blahblah.bat

  1. Right-click on the Project in question右键单击有问题的项目
  2. A context menu will show up将显示一个上下文菜单
  3. Select the Properties option选择属性选项
  4. Select “Build Events”选择“构建事件”
  5. Click on “Edit Post-build…”单击“编辑构建后...”
  6. Enter the aforementioned command that I posted above, and tailor it to your needs before pressing OK.输入我在上面发布的上述命令,并根据您的需要对其进行调整,然后再按 OK。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM