Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run interactive batch in Visual Studio post build events

I have a program written in vb.net. After I build, I want to launch an interactive batch file that executes a psexec command remotely. 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". In a normal command prompt, it works fine. But in a Visual Studio post build event it goes down. Help me!

like image 312
davymartu Avatar asked Oct 11 '13 14:10

davymartu


People also ask

How do I run a batch file in post build event?

If you go to the Properties page for your project, you should select the Build Events tab. You can type in the call to your batch file in the Post-build event command line text box. If you want to refer to the batch file using the paths included in the project or solution, you can click on the Edit Post-Build...

How to use Post build event in Visual Studio?

In the Post-build event command line box, specify the syntax of the build event. Add a call statement before all post-build commands that run . bat files. For example, call C:\MyFile.

How do I debug a post build event in Visual Studio?

Another way is to check the bin\debug dir for 'PreBuildEvent. bat' or 'PostBuildEvent. bat' which are the file that Visual Studio creates and run during the build events, if there is an error the files remain in the output dir and you can run them manually and spot the error.

How do I open a build event in Visual Studio?

Go to Solution Explorer and right-click on the project then select Properties then go to the Build Events tab.


1 Answers

I've done this before using the start command. I created a simple pause.bat file to demonstrate:

    @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
like image 170
DSway Avatar answered Sep 24 '22 01:09

DSway