private String runPythonScript(ResourceFile scriptFile, GhidraState state) throws Exception {

		runSwing(() -> console.clearMessages());

		JythonScriptProvider scriptProvider = new JythonScriptProvider();
		PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
		JythonScript script = (JythonScript) scriptProvider.getScriptInstance(scriptFile, writer);
		script.set(state, new ScriptControls(writer, writer, TaskMonitor.DUMMY));
		script.run();

		waitForSwing();

		AtomicReference<String> ref = new AtomicReference<>();
		runSwing(() -> {
			String text = console.getText(0, console.getTextLength());
			ref.set(text);
		});

		String text = ref.get();
		return text;
	}
Runs the given Python script with the given initial state.

@param scriptFile The Python script to run.
@param state The initial state of the script.
@return The console output of the script.
@throws Exception If an exception occurred while trying to run the script.
Ghidra/Features/Jython/src/test.slow/java/ghidra/jython/JythonScriptTest.java