jEdit Community - Resources for users of the jEdit Text Editor
Solution: Launching External Apps From Macros
Submitted by ehtyar on Wednesday, 1 April, 2009 - 00:25
Hi guys.

When i first moved to jEdit, I was extremely frustrated by the way Java launches external apps (via Runtime.getRuntime().exec()). It decided internally whether or not you should see a console window for a console program and other stupid stuff like that. There are solutions all over the place using cmd /c and cmd /k to remedy this problem, but that all gets very messy when you're dealing with batch files.

To solve this problem, I downloaded ShellExecute by OptimumX (http://www.optimumx.com/), which basically just uses ShellExecuteEx() to launch the app specified on the command line. When launching apps via this utility, they behave as you would expect them to.

To use it, put it in your jre bin directory, or somewhere in your path environment variable, and use it in your macro like so:

path = buffer.getPath().substring(0, buffer.getPath().lastIndexOf("\\"));
Process proc = Runtime.getRuntime().exec("ShellExecute.exe /F:cmd.exe", null, new File(path));

That example macro will open a command prompt in the directory containing the document of the current buffer.

Hope this helps some people out.

Ehtyar.
User login
Browse archives
« November 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300