Process waitFor command

M

Matthew Zimmer

Hey all,
I'm working on a program where I open up a word document using the exec
command like this:
Process p = r.exec(...); // this works fine

I then want to receive notification from Windows when word is done with
the file. I can kind of do that by using the waitFor method on Process
like this:
int res = p.waitFor();

This basically worked in most cases. As soon as I shut down word, my
program resumes after the waitFor command. However, if I open up the
word document at a time when another file is open in word something
weird happens. It appears that windows creates a new instance of word,
then opens the file in another instance, then shuts down the original
instance which is the one that waitFor is waiting for. Thus, even
though the file is open, the original process closes which means that I
get to the next line in my code well before it should be there.

Does anybody have any idea how to stop this? I've tried using the whole
exclusive open in java io, but that doesn't work at all. Thanks for any
help.
Matthew
 
N

Neil Campbell

Matthew said:
Hey all,
I'm working on a program where I open up a word document using the exec
command like this:
Process p = r.exec(...); // this works fine

I then want to receive notification from Windows when word is done with
the file. I can kind of do that by using the waitFor method on Process
like this:
int res = p.waitFor();

This basically worked in most cases. As soon as I shut down word, my
program resumes after the waitFor command. However, if I open up the
word document at a time when another file is open in word something
weird happens. It appears that windows creates a new instance of word,
then opens the file in another instance, then shuts down the original
instance which is the one that waitFor is waiting for. Thus, even
though the file is open, the original process closes which means that I
get to the next line in my code well before it should be there.

Does anybody have any idea how to stop this? I've tried using the whole
exclusive open in java io, but that doesn't work at all. Thanks for any
help.
Matthew

Quite a lot of apps work like this, and it can be annoying. However, there
is usually an option you can set to force it to open in a new instance.

I can't test any of them as I don't have Word, but there are some switches
listed in http://support.microsoft.com/default.aspx?scid=kb;EN-US;210565
that may help you.
 
M

Matthew Zimmer

Neil said:
Matthew Zimmer wrote:




Quite a lot of apps work like this, and it can be annoying. However, there
is usually an option you can set to force it to open in a new instance.

I can't test any of them as I don't have Word, but there are some switches
listed in http://support.microsoft.com/default.aspx?scid=kb;EN-US;210565
that may help you.

Thanks. It turns out that using "/n" which "opens up a new instance of
word with no document" does NOT work, but using "/w" which "opens up a
new instance of word with a blank document" DOES work. I have no clue
why one works and the other doesn't, but that's MS for you. :) Of
course, if anybody knows how I can make the waitFor work for anything
I'd appreciate any other thoughts, but thanks again for helping me with
this one.
Matthew
 
X

X_AWemner_X

I'm working on a program where I open up a word document using the exec
Thanks. It turns out that using "/n" which "opens up a new instance of
word with no document" does NOT work, but using "/w" which "opens up a
new instance of word with a blank document" DOES work. I have no clue
why one works and the other doesn't, but that's MS for you. :) Of
course, if anybody knows how I can make the waitFor work for anything
I'd appreciate any other thoughts, but thanks again for helping me with
this one.

Most likely will need a native wrapper to handle windows processes. You
basicly launch "myprocessrunnerwrapper.exe <params>" and wait for it to
exit. If word really opens up a new process with different PID then it needs
a tricks to overcome the problem. Probably Excel does same.
 
M

Matthew Zimmer

X_AWemner_X said:
Most likely will need a native wrapper to handle windows processes. You
basicly launch "myprocessrunnerwrapper.exe <params>" and wait for it to
exit. If word really opens up a new process with different PID then it needs
a tricks to overcome the problem. Probably Excel does same.

I think you're right on this one. I'll probably end up having to do
exactly that, but was really hoping to be able to avoid it. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top