Can I run a batch file (.bat) from within the IDE?

Hello,

I have a batch (.bat) file (with only one line of code in it) that recompiles sass files. This bat file is inside my project files of course. So far I always just navigated to its location using windows explorer and ran it. But I was wondering if it's possible to run this bat file from withing the IDE as opposed to going to explorer all the time?

Eg, could I just select the bat file in the project file list and ran it somehow?

Thanks!

4 comments

Hi there,

Multiple ways:

  1. Instead of manually navigating in Explorer -- just use "Navigate | Select in... | Explorer (Alt+F1, 8)" on such bat file and IDE will open Explorer with that file already selected
  2. Create yourself some External Tool (Settings | External Tools) that will call cmd.exe and pass bat file name (and whatever else is required) as a parameter. You can then right click on such bat file in Project View (or whatever) and invoke that External Tool entry. Alternatively -- assign specific shortcut to it.
  3. Use CMD Support plugin http://plugins.jetbrains.com/plugin/?webide&pluginId=5834  -- it is not compatible with latest versions (throws some errors from time to time) but the execution of bat file should still work.
  4. Convert your bat file into simple Phing build.xml -- IDE has good integration with Phing via Phing Support plugin (bundled with PhpStorm already). Hint -- you will need to use <exec task for this


P.S.
v6 can now autocompile SASS (any any other) files on Save via File Watchers plugin

1

Thanks, sound great!

However, I need some help. It seems like I'm not able to accomplish running the cmd. I tried option #2, to create an external tool.

I have a batch file called "compass-compile.bat". Inside this batch file a single command "compass compile". Normally I just couble click this batch file in Windows Explorer and it will just compile my sass file. So this is what I tried:

1. I invoked Settings > External Tools and Add a new tool.
2. Under Tool Settings I have:

  • Program: C:\Windows\System32\cmd.exe
  • Parameters: compass compile
  • Working Directory: D:\wamp\www\sencha\CU-iPad\resources\scss\

3. This just opens the console window and doesn't do anything. So I tried chaning the Tool settings to

  • Program: C:\Windows\System32\cmd.exe compass compile
  • Working Directory: D:\wamp\www\sencha\CU-iPad\resources\scss\

4. Same result. Nothing. So then

  • Program: C:\Windows\System32\cmd.exe
  • Parameters: compass-compile.bat
  • Working Directory: D:\wamp\www\sencha\CU-iPad\resources\scss\

5. Nothing. Next:

  • Program: C:\Windows\System32\cmd.exe compass-compile.bat
  • Working Directory: D:\wamp\www\sencha\CU-iPad\resources\scss\

6. Nothing. Next:

  • Program: C:\Windows\System32\cmd.exe
  • Working Directory: D:\wamp\www\sencha\CU-iPad\resources\scss\compass-compile.bat

7. Error, because working directory is not a working directory (obviously, but just tried)

I'm out of ideas. I think I've tried all possible combinations. I have no idea why I'm not able to automatically run this this batch file. I did read the help file, but didn't help me figure out what am I doing wrong. Any ideas?

Thanks.

0

Well .. if you have .bat file, then you may use it directly in "Program" field -- it depends what that bat file does (what other programs/batch files it calls) and what output you expect to see. For me, not all bat files were working fine (the final result/output, not just execution) if invoked directly, that's why I prefer going via cmd.exe route (possibly it is just my specific environment, don't know for sure).

When going via cmd.exe, you just need to check how it works (cmd.exe /?). They key here -- you need to use /C (or /K if so required) parameter to execute another command. This is what I do when executing phpunit outside IDE (executing specific test file):

Program: cmd.exe
Parameters: /C "phpunit $FilePath$"
Working directory: $ProjectFileDir$\tests\

In your case it MAY look like this (I'm assuming that compass-compile.bat is located in D:\wamp\www\sencha\CU-iPad\resources\scss\):
Program: cmd.exe
Parameters: /C "compass-compile.bat"
Working directory: $ProjectFileDir$\resources\scss\

0

In your case it MAY look like this (I'm assuming that compass-compile.bat is located in D:\wamp\www\sencha\CU-iPad\resources\scss\):
Program: cmd.exe
Parameters: /C "compass-compile.bat"
Working directory: $ProjectFileDir$\resources\scss\


That's what it was! It's working! Thank you!
0

Please sign in to leave a comment.