I've come across the following code recently:
Process proc1 = Runtime.getRuntime().exec("C:\\Program Files (x86)\\...");
This is working great. However, an intresting problem. This code actually opens a new instance of the specified process and stores it to the object. It doesn't target that process if its already running and store it to the object. I'm guessing thats the .exec() function call which is doing that. How can I target an already active process and store it to my Process object without opening a new instance?
Note: I tried the obvious answers, Process proc1 = new Process("name");
Eclipse says Process cannot be instantiated. I did lookup the Runtime class in the javadoc. As far as I can tell, there is no obvious method that does what I'm trying to achieve. Seems like a simple qustion, I'm sure its been asked before but I couldn't find the answer anywhere which is why I'm asking here. I may be using the wrong terminology which is why.
EDIT: I'm on Windows 10
My objective is to attatch the process of the game Minecraft to a Process
object. Then, I want to move my character forward using robot.keyPress(KeyEvent.VK_W);
. I can't just open the process minecraft because all that would do is open the launcher minecraft.exe and then I'd be on a "welcome" screen.