private void callGpsBabel() throws Exception
	{
		// Set up command to call gpsbabel
		final String command = Config.getConfigString(Config.KEY_GPSBABEL_PATH);
		String[] commands = null;
		final String device = _deviceField.getText().trim();
		final String format = _formatField.getText().trim();
		if (_waypointCheckbox.isSelected() && _trackCheckbox.isSelected()) {
			// Both waypoints and track points selected
			commands = new String[] {command, "-w", "-t", "-i", "gpx", "-f", "-", "-o", format,
				"-F", device};
		}
		else
		{
			// Only waypoints OR trackpoints selected
			commands = new String[] {command, "-w", "-i", "gpx", "-f", "-", "-o", format,
				"-F", device};
			if (_trackCheckbox.isSelected()) {
				commands[1] = "-t";
			}
		}
		// Save GPS settings in config
		Config.setConfigString(Config.KEY_GPS_DEVICE, device);
		Config.setConfigString(Config.KEY_GPS_FORMAT, format);

		String errorMessage = "";
		Process process = Runtime.getRuntime().exec(commands);

		String trackName = _trackNameField.getText();
		if (trackName == null || trackName.equals("")) {trackName = "prune";}
		// Generate the GPX file and send to the GPS
		OutputStreamWriter writer = new OutputStreamWriter(process.getOutputStream());
		boolean[] saveFlags = {true, true, true, true, false, true}; // export everything
		GpxExporter.exportData(writer, _app.getTrackInfo(), trackName, null, saveFlags, false);
		writer.close();

		// Read the error stream to see if there's a better error message there
		BufferedReader r = new BufferedReader(new InputStreamReader(process.getErrorStream()));
		String line = null;
		String errorMessage2 = "";
		while ((line = r.readLine()) != null) {
			errorMessage2 += line + "\n";
		}
		// Close error stream
		try {
			r.close();
		} catch (Exception e) {}
		if (errorMessage2.length() > 0) {errorMessage = errorMessage2;}
		if (errorMessage.length() > 0) {throw new Exception(errorMessage);}
	}