0

I just downloaded MCP to see how things work behind the scenes in Minecraft.

Inside MCP there are a bunch of batch files that you use to do things like: decompile, recompile, startclient, etc.

What I would like to be able to do is run these batch files from a basic java gui.

I'm good with the gui part but I havent got a clue how to run those batch files.

Here is an example of one of the batch files:

The file is at:

C:\MCP\startclient.bat

startclient contains the following:

@echo off

:try_python
set PYTHON=python
%PYTHON% --version >NUL 2>NUL
if errorlevel 1 goto try_python_mcp
goto foundit

:try_python_mcp
set PYTHON=runtime\bin\python\python_mcp
%PYTHON% --version >NUL 2>NUL
if errorlevel 1 (
    echo Unable to locate python.
    pause
    exit /b
)

:foundit
%PYTHON% runtime\startclient.py conf\mcp.cfg
pause

Can it be done?

1
  • I am surprised they do not offer an x-plat build.xml or similar. What decade(/millennium) are they developing in? Commented May 27, 2011 at 22:30

1 Answer 1

4

You can easily run a batch file from java using Runtime:

Process p = Runtime.getRuntime().exec("cmd /c start " + yourbatchFileName);

you can also grab I/O of the process, using p.getOutputStream(), p.getInputStream() etc.

See more about the Process class here.

And I suggest you take a look at this article as well.

Sign up to request clarification or add additional context in comments.

10 Comments

But this would be outside JVM.
Batch files are not intended for java, but for (usually) windows cmd, this is the only way I know about running those from java with maximum control.
Good call on adding the link to the Java World 'gotchas' article. Anybody that attempts to use a Process needs to read that, sooner or later.
So I plugged in: Process p = Runtime.getRuntime().exec("cmd /c start C:\\MCP\\recompile.bat");
But when it pops up it complains: Unable to locate python. Then it exits to the java project folder, not the MCP folder? Might be noobish but, do I need to start cmd in the MCP folder for it to work?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.