In my java project I need to run VLC Media Player (for steaming) and on request I want to stop streaming. In Linux, I have created following bash script, which runs the VLC process with some arguments and then outputs it's ID to standart output:
cvlc $@ &
echo $!
Then I have following java code which runs the script and reads it's ID from stdin:
Process proc = Runtime.getRuntime().exec("/path/to/script");
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = br.readLine();
if(line!=null) {
lastPID = new Integer(line);
System.out.println("Last vlc PID=" + lastPID);
}
When I want to stop streaming, I will kill process with corresponding ID:
Runtime.getRuntime().exec("kill " + lastPID);
Is there any way to write equivalent script in Windows 7 (cmd.exe or Windows PowerShell)? Alternatively, is there a way to write pure (platform independent) java code which runs process, then gets it's ID and stops it?