Index: /applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
===================================================================
--- /applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java	(revision 29816)
+++ /applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java	(revision 29817)
@@ -43,4 +43,5 @@
 import javax.swing.JTextField;
 import javax.swing.JToolBar;
+import javax.swing.SwingUtilities;
 
 import org.openstreetmap.josm.Main;
@@ -238,6 +239,11 @@
     }
 
-    protected void printHistory(String text) {
-        historyField.setText(text);
+    protected void printHistory(final String text) {
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                historyField.setText(text);
+            }
+        });
     }
 
@@ -478,5 +484,4 @@
         // redirect child process's stderr to JOSM stderr
         new Thread(new Runnable() {
-            @Override
             public void run() {
                 try {
@@ -497,5 +502,4 @@
         // Write stdin stream
         Thread osmWriteThread = new Thread(new Runnable() {
-            @Override
             public void run() {
                 BBox bbox = null;
@@ -516,7 +520,15 @@
                         bbox.addPrimitive(primitive, 0.0);
                 }
+                osmWriter.writeNodes(new SubclassFilteredCollection<OsmPrimitive, Node>(contents, OsmPrimitive.nodePredicate));
+                osmWriter.writeWays(new SubclassFilteredCollection<OsmPrimitive, Way>(contents, OsmPrimitive.wayPredicate));
+                osmWriter.writeRelations(new SubclassFilteredCollection<OsmPrimitive, Relation>(contents, OsmPrimitive.relationPredicate));
+                osmWriter.footer();
+                osmWriter.flush();
+
                 for (Parameter parameter : parameters) {
                     if (!parameter.isOsm())
                         continue;
+                    contents = new ArrayList<OsmPrimitive>();
+                    osmWriter.header();
                     pObjects = parameter.getParameterObjects();
                     for (OsmPrimitive primitive : pObjects) {
@@ -527,10 +539,11 @@
                             bbox.addPrimitive(primitive, 0.0);
                     }
-                }
-                osmWriter.writeNodes(new SubclassFilteredCollection<OsmPrimitive, Node>(contents, OsmPrimitive.nodePredicate));
-                osmWriter.writeWays(new SubclassFilteredCollection<OsmPrimitive, Way>(contents, OsmPrimitive.wayPredicate));
-                osmWriter.writeRelations(new SubclassFilteredCollection<OsmPrimitive, Relation>(contents, OsmPrimitive.relationPredicate));
-                osmWriter.footer();
-                osmWriter.flush();
+                    osmWriter.writeNodes(new SubclassFilteredCollection<OsmPrimitive, Node>(contents, OsmPrimitive.nodePredicate));
+                    osmWriter.writeWays(new SubclassFilteredCollection<OsmPrimitive, Way>(contents, OsmPrimitive.wayPredicate));
+                    osmWriter.writeRelations(new SubclassFilteredCollection<OsmPrimitive, Relation>(contents, OsmPrimitive.relationPredicate));
+                    osmWriter.footer();
+                    osmWriter.flush();
+                }
+
                 if (tracks) {
                     final GpxWriter gpxWriter = new GpxWriter(printWriter);
@@ -545,17 +558,14 @@
                 }
                 Utils.close(osmWriter);
-                synchronized (syncObj) {
-                    tp.running = false;
-                    syncObj.notifyAll();
-                }
             }
         });
 
         // Read stdout stream
-        final OsmToCmd osmToCmd = new OsmToCmd(this, Main.main.getCurrentDataSet());
+        final DataSet currentDataSet = Main.main.getCurrentDataSet();
+        final CommandLine that = this;
         Thread osmParseThread = new Thread(new Runnable() {
-            @Override
             public void run() {
                 try {
+                    final OsmToCmd osmToCmd = new OsmToCmd(that, currentDataSet);
                     String commandName = currentCommand.name;
                     //HashMap<Long, Long> inexiDMap = new HashMap<Long, Long>();
@@ -564,6 +574,11 @@
                     final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList();
                     if (!cmdlist.isEmpty()) {
-                        SequenceCommand cmd = new SequenceCommand(commandName, cmdlist);
-                        Main.main.undoRedo.add(cmd);
+                        final SequenceCommand cmd = new SequenceCommand(commandName, cmdlist);
+                        SwingUtilities.invokeLater(new Runnable() {
+                            @Override
+                            public void run() {
+                                Main.main.undoRedo.add(cmd);
+                            }
+                        });
                     }
                 }
