From: S-Y. Chen on
On Jul 16, 4:04 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com>
wrote:
> On Jul 16, 6:20 am, "S-Y. Chen" <shenyeh_c...(a)hotmail.com> wrote:
>
> > I think I forgot to say, this is Windows.
>
> Oh ! (you said it 'forked', so I had a bit of hope... too bad)
>
> > So the child process here is a package called comsol, and the
> > grandchild is a package called matlab.
>
> > We have confirmed that, when comsol is already terminated, matlab is
> > still going on. And only when matlab is done, the file "file01.txt"
> > will be created and saved.
>
> Ok I googled a bit and found the idiom you are using at
>
>  http://www.comsol.com/support/knowledgebase/980/
>
> while I have no idea of the details making you use comsol vs.
> comsolbatch, it looks like the former is more oriented towards
> interactive display (but the window-suppressing flags are puzzling in
> that case). Is it possible for you to use comsolbatch instead ?
>
> If not, I'm afraid you're stuck with digging through the comsol.exe
> documentation and/or support to convince the sucker to _wait_ for its
> child. Given the documented "dosomething, exit" argument to the matlab
> child, it would be normal for comsol.exe to have a /waitforchild flag.
> But in Windows you never know :/
>
> -Alex
>
> PS: if you really can't do otherwise, try adding to the end of your
> matlab script (before exit) something that creates yet another
> signalling file, after closing the result file. This way, by
> monitoring the second one you're sure that the first is closed.


Well that is what I am trying to do later.

But this raises to another question : is it possible to check whether
a file is still opened by another program ?

I have been thinking about creating another dummy file in the end of
matlab too. But, just in case, if the loop come back faster then the
file being closed by matlab, it will cause problem again.

Any hint ?

Regards
S-Y. Chen



From: Craig on
S-Y. Chen wrote:
>>> I think I forgot to say, this is Windows.
....
> But this raises to another question : is it possible to check whether
> a file is still opened by another program ?

In general, Windows file systems aren't happy when multiple programs try to
write or even access the same file at the same time - which is why you get Word
or Excel dialogs asking if you want to open something up in read only mode. So,
yes, you probably could figure out how to do this, and it may be why you have
multiple matlab instances hung up trying to access the same file.

On the other hand, this idea seems more fruitful:
Can you tell when you are at the end of the output file? Why don't you insert
something at the end of your output file, like, say, "End of File". Then exec
your program, wait for the file to show up, read until the end of the file,
delete or move it, and then go on.

craig
From: Craig on

Craig wrote:
> S-Y. Chen wrote:
>>>> I think I forgot to say, this is Windows.
> ...
>> But this raises to another question : is it possible to check whether
>> a file is still opened by another program ?

check this out, too:

http://twapi.magicsplat.com/disk.html#begin_filesystem_monitor
From: Aric Bills on
On Jul 16, 10:57 am, Craig <ask...(a)somewhere.net> wrote:
> S-Y. Chen wrote:
> >>> I think I forgot to say, this is Windows.
> ...
> > But this raises to another question : is it possible to check whether
> > a file is still opened by another program ?
>
> In general, Windows file systems aren't happy when multiple programs try to
> write or even access the same file at the same time - which is why you get Word
> or Excel dialogs asking if you want to open something up in read only mode. So,
> yes, you probably could figure out how to do this, and it may be why you have
> multiple matlab instances hung up trying to access the same file.
>
> On the other hand, this idea seems more fruitful:
> Can you tell when you are at the end of the output file? Why don't you insert
> something at the end of your output file, like, say, "End of File". Then exec
> your program, wait for the file to show up, read until the end of the file,
> delete or move it, and then go on.
>
> craig

It's been years since I've done anything with Word and Excel, but I
thought the mechanism that allowed them to tell if a file was already
open was the existence of a specific temporary file that was deleted
when the document was closed. I don't think Windows has any qualms
about multiple programs accessing a file simultaneously for reading,
although I don't know about writing.
From: Craig on
Aric Bills wrote:

> It's been years since I've done anything with Word and Excel, but I
> thought the mechanism that allowed them to tell if a file was already
> open was the existence of a specific temporary file that was deleted
> when the document was closed. I don't think Windows has any qualms
> about multiple programs accessing a file simultaneously for reading,
> although I don't know about writing.

try this experiment:
create a csv file
open it with excel
now open it in emacs, edit it and try to save the changes.
get back to me on the results :-)