-1

I'm trying to do a program which modifies source code from another program and then stops the program.

The basic idea is that when program "A" runs, it will compile and run program "B". When I put some text file with some format in an specific directory, program "A" will detect that and stops program "B", modify program "B" source code with whatever it finds in the text file, and then compile and run program "B" again.

The behavior will be pretty much alike of what an IDE does when we compile, run and stops programs when we are coding, but it can't be done by the user, it has to be automatic. I have find some examples on how to compile and run, but not on how to stop.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
sjrm
  • 19
  • 2

2 Answers2

0

I wrote something similar that could monitor/stop a Windows process by using WMI (Windows Management Instrumentation). The obstacle is WMI API is implemented with C++, C# or VB, which only leaves two paths. First wrap C++ code in JNI or write a C# webservice to access WMI in Java.

BK Batchelor
  • 457
  • 2
  • 6
0

The ProcessBuilder class can be used to start a process, and it returns a Process instance that you can use to stop that process.

You can also control compilation from within a Java program by using javax.tools.JavaCompilerTool.

Community
  • 1
  • 1
Jay Elston
  • 1,978
  • 1
  • 19
  • 38