Configure Intellij IDEA to run batch file - batch-file

I'm using InteliJ IDEA (Community addition) and I found myself doing some file transfers to and from the project folder.
After reapeating the task for a while I've created some batch scripts that transfering the files automaticly. Now, I'll be much more happy if I could run the scripts directly from the IDE - by pressing a button for example...
Question is: Can I add buttons to IntelliJ IDE - that will run a batch file? If it's possible I'll be happy to know how it can be done.
Thanks!

You can use "External Tools" to invoke any program
Goto Settings->External Tools and create a tool which will open the following dialog choose the batch file for Program.
Then the tool will be available in the menu Tools
Ref:External Tools
Update:
If you want to link an 'External Tool' to a 'Button' in the toolbar check How to add buttons linked to your external tool in InteliJ IDEA

Also if you install "Batch Scripts Support" plugin, you will get nice file context menu actions for running batch files directly from the project view.
NOTE 2019: The original authors abandoned the plugin, but there is a maintained fork for current versions of IntelliJ: https://github.com/SimonIT/idea-batch
NOTE 2020: Even newer fork is: https://github.com/aefimov/idea-batch

Another alternative to IntelliJ 2019 is:
Edit Configuration > Click '+' > Select Shell Script > 'In Script path:' set the .bat file location > OK > Click play button or Run once you have saved it
See image below:

Install "Batch Scripts Support" plugin. Then choose + -> Batch:

Related

background process launched by TFS is killed when switching to next step

I have some trouble keeping alive a background process when launched by TFS.
Usually I use a batch that launch a java server (new window), as long as I keep this window open it works properly.
C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\server.bat
In order to make my process automatic, I include this in TFS. In the step I call a batch that contains the following:
cd C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk // necessary to find the batch
start C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\server.bat
In my task manager, I can see in background tasks that java is launched (no new window is opened), exactly as it behaves when launching directly the batch. But after a few seconds, when TFS switches to the next step, it stops.
Then the next step carries on but fails as it requires the server to be launched.
Is there a particular way of doing it in TFS ?
thank you
Alexandre
It's suggest to launch the .bat file from a relative path not directly use cd to hard code the path.
Also recommend you to use Run Batch File task not Run Command Line task to launch the .bat file.
According to your description, seems you are using a run command line task in your build pipeline. Then run the command under the working directory c:\Build_work\5\s, the command cd to C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\ on the build agent, find the server.bat, run the server.bat.
First check if the .bat file is located at the path you are specifying on the build agent. Not sure if the bat file have to run under C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\, guess you are also hard code the path in your server.bat file. Suggest you change all the path to relative path, you could use some built-in variable in TFS.
As for your workaround in comment, seems you want to chain builds in TFS. The official docs literally say "not yet" and have a uservoice in planed. However you could use some workaround, such as create or use other's customize extension (use rest api) to call another build. Detail ways please refer huserben's answer in this question: How to chain builds in TFS 2015?
Note sure you have to go deep into this area for your original issue. Just add some related info in case you are interested or need.
Well,
Just in case someone else goes through the same kind of issue, I found a workaround:
I wish to mix different command line steps, some of them launching Python scripts:
I have one step for launching the server that is required for my testing tool, one step for my testing tool and one Python step for differential testing
I realized that I could embed everything in a Python script.
It can handle server launching process in a separate window (with subprocess), launch my Python part and launch another process for my validation tool.
I have to test the whole chain but, at least, I solved my problem of launching a background process and detach it from TFS

Automate Build script from Batch to MSBUILD/NANT

I am trying to automate a build process for a C# (vs2008) solution.
The build script is written in a Batch script which I want to change. We use Clearcase as the CM system. I have searched some tools such as MSBUILD, NANT.
Any suggestions which is a better solution like a sample script in MSBUILD and NANT?
I have not seen any sites where MSBUILD and NANT is documented well or any good tutorial about each task description.
Where I can learn MSBUILD or NANT either of them and write script from scratch?
There is a third way which I prefer. You can also use devenv.com. It's faster than NANT, doesn't require NANT bins and works on any machine with VS installed. You also avoid possible errors with MSBUILD (http://support.microsoft.com/kb/964125).
Just use %path_to_devenv.com%\devenv.com "%path_to_sln" /<buildoption> BuildConfig
In my case it's
%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com "C:\Projects\XYZ\xyz.sln" /rebuild Debug
This way it's guaranteed that your project will be build exactly the same way as it's being built in Visual Studio.
EDIT:
Now that we know how how much there is to do, I'll try to give an outline how you can setup the whole system for automated build controll.
Set up your repository (I hope this is already done - tell me if not)
Install and set up Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins) including users, ClearCase-Credentials, plug-ins for ClearCase, MSBuild, etc. (all of them can be found in the Jenkins plug-in interface) - this is the biggest peace of work
Create and set up a new project in the jenkins interface (name, working directory, etc.)
Tell jenkins to use source code management (e.g. subversion module), enter the ClearCase repos to use, set the desired behavior of the source code management
Set a build trigger (I recommend checking the source code management each minute: * * * * *)
Add a build step and select "Build a Visual Studio project or solution using MSBuild" - this option should appear after installation of the MSBuild plugin (https://wiki.jenkins-ci.org/display/JENKINS/MSBuild+Plugin)
Set the path to the .sln file (you have checked it out from your repository)
Add more optional arguments if desired (eg /p:Configuration=Release or Debug or whatever http://msdn.microsoft.com/en-us/library/vstudio/ms164311%28v=vs.110%29.aspx)
Play around untill it works
Btw., I recommend to put all external dlls into your repository.

how to make installer (exe) file in windows

I have created a WPF application. I want to make installer file (exe) for this application.
This application also uses some other 3rd party files (bat files); which i have zipped.
I want to unzip this file while installing and set the path of unzipped dir in Path variable also.
I got a link http://www.msdotnet.co.in/2012/06/how-to-create-setup-fileexe-file-from.html#.U3GT7YGSzxp
which tells how to create a installer file.
How to achieve unzipped part and setting environment vairable while making installer?
Thanks
Take a look at wix from Microsoft.
It can be run standalone, but is great run from within visual studio. You write a small xml file detailing what you want installed, and it does the rest.
To run a zip command, use a CustomAction.
Search for Install-shield. It is old tool but having good scripting capability like what you are expecting (i.e) Unzipping the folder and dealing with path environment variable
Use Inno Setup (http://jrsoftware.org/isinfo.php) or NSIS (http://nsis.sourceforge.net/Main_Page).
Both are free (open source) installation systems with many possibilities and huge community around (even here on SO).
They are really easy to use (especially Inno) and they are powerful so it is easy to achieve your required functionality.
Take a look at Stall:
https://github.com/jamesqo/Stall
It's an OSS project that lets you install your app from the command line, no configuration required.
Example Usage:
stall path/to/YourApp -e YourApp.exe -i YourApp.exe
This installs your app straight to the user's computer without having to make an intermediary MSI.
If you have to unzip files as well, you may want to just consider a simple batch files that downloads the binaries + unzips the contents + runs Stall.

open appengine file in netbeans

From the appengine launcher on Windows, one of the buttons at the top is 'edit'. You can set the external editor in 'preferences'. The default is Wordpad. I wanted to use netbeans, but I can't figure out how to make GAE open netbeans. I have done many searches but I keep getting hits about creating a .exe file in netbeans, which is not what I want. I see no 'netbeans.exe' file. I tried C:\Program Files\NetBeans 7.3.1\platform\core\core.jar but that does nothing. Thank you.
netbeans is a GUI for java SDK. it is not a text editor. it has a text editor somewhere in it, but it is not obvious where and it may not be possible to call the editor alone from outside.
I suggest you start netbeans, edit the file in it and then either launch the project from the launcher or from the command line. no need to compile, as soon as you save the edit, you can re-load the page.

Missing "Run as Administrator" in VS Installer's Shortcut

I created a shortcut from the application .EXE in Visual Studio Installer, but the resulting shortcut did not have the option of "Run as Administrator" when I right-clicked the shortcut icon.
The application .EXE in Program Files does allow this option on right-click. If I created the shortcut manually from the .EXE (i.e. "Create Shortcut") instead of from the deployment, then the resulting shortcut also has that option.
How to a deploy an application in Visual Studio Installer to include a shortcut that has "Run as Administrator" option enabled on right-click?
I spent ages looking for a solution to this. Amazing, really, as it must be the case for all Visual Studio installer projects.
I'm using Visual Studio 2017 Community at the time of writing and I can't see any option to do this from within the IDE.
Apparently this is an issue with the resulting .msi where the shortcut created is an "advertising shortcut". I'll leave you to discover what you want to know about that in your own time. (Personally, I don't care.)
What you need to do is force the shortcut to be "non-advertising".
This is the better of the two solutions I've found squirreled away in SO. I think it's better because it 1) doesn't include adjusting your installer project for each solution and 2) doesn't involved manually editing the .msi file after every build.
Full credit to the guys on this SO post for this solution, btw. You know who you are. I'm posting because it's not obvious from the question that it will solve this particular problem.
What you do is make a generic change to the msi creation schema file so that the change propagates to all of your future builds. You'll need Orca to make the initial change.
Download the Windows SDK Installer here.
Select "MSI Tools" in the installer.
Install Orca-x86_en-us found in {Installation Folder}\Windows Kits\10\WindowsSDK\Installers.
Find the file "Schema.msi" which is located somewhere like {Visual Studio Program Folder}\Common7\IDE\CommonExtensions\Microsoft\VSI\bin\VsdSchema.
Open "Schema.msi" in Orca.
Copy the folder to the Desktop if it is read only and replace the original after step 9.
Select the "Property" table on the left.
Add a table row with property DISABLEADVTSHORTCUTS and value "1" (true).
Save the file and close Orca.
Rebuild your installer project and (re-)deploy your application.
Enjoy the ability to "Run as administrator"!
A final note: I've found that updates to Visual Studio can overwrite the change you've made, once again removing the "Run as Administrator" context option. So check the msi file after each update.
If you have a manifest, you can require to have administrator privilege, add the following to your manifest
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
see http://msdn.microsoft.com/en-us/library/bb756929.aspx
You can also run any filetype as administrator with the help of the registry, see http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/

Resources