Update:
There were some great solutions, but I realized that there is a problem in my premise: It seems that the rt.exec will not reach back to the java code once the process has been executed. Thank you for all your help!
I want to take a screencap every second programmatically and the title of each screencap should be the timestamp. I'm using vlc to achieve this.
starttime = System.nanoTime();
screencapProcess = rt.exec("C:\\VLC\\vlc screen:// --dshow-vdev=screen-capture-recorder --dshow-fps=1 -I dummy --dummy-quiet --rate=1 --video-filter=scene --vout=dummy --scene-format=jpg --scene-ratio=1 --scene-prefix=snap --scene-path=" + path +" --scene-prefix="+ "ScreenCapAt" + ( String.valueOf(((long)System.nanoTime() - starttime)).substring(9, 14))+" vlc://quit ");
The relevant part is:
String.valueOf(((long)System.nanoTime() - starttime)).substring(9, 14))
This cause an index out of bounds exception for nanoTimes less that 1.
I can't declare "System.nanoTime() - starttime" as a variable outside this line to get it's length since that would change my times.
Is there a way to get the last 5 digits of this undeclared variable of unknown length on one line?
This answer needs to fit in my rt.exec line.
Some thoughts:
- Bitwise shifting and masking.
- Piping into my .exec
- postprocessing
- Creating a new class
- Calling System.nanoTime() - starttime again would increase the time of the operation and throw off my calculations.
- Is there a better way to atomically get the time of capture?