开发者

Have to use a thread sleep procedure to get document updated

I have a Word macro that needs to run using Java. So I use a VB script to run the macro as below. It d开发者_StackOverflow中文版oes some editing in the Word document and I use that "test.doc" to read as an InputStream. But I have to sleep the main thread for a while to get the document changes in the "test.doc" file (varies the time needed to thread sleep time from document to document). As shown in code. I am a bit confused because I wait for the process to end. And still the document is not updated? Can someone please help me here?

Process proc = Runtime.getRuntime().exec("cmd /c start C:\\test.vbs");
proc.waitFor();
Thread.currentThread().sleep(2000);
InputStream uploadedFileStream = new BufferedInputStream(new FileInputStream("c:\\test.doc"));


Get rid of "start", so the created instance of Word doesn't run in the background, and the sleep which is now unnecessary.


The above willspawn off the application for test.vbs in the background. So unfortunately it's not going to wait for Word at all.

I would either spawn Word directly, or record the modification time of test.doc and watch for that changing (by sleeping and checking every few seconds). The latter is not a particularly good approach, btw.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜