Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: waiting command

  • To: mathgroup at
  • Subject: [mg40243] Re: waiting command
  • From: Jens-Peer Kuska <kuska at>
  • Date: Fri, 28 Mar 2003 04:28:05 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <b5uono$lkb$>
  • Reply-to: kuska at
  • Sender: owner-wri-mathgroup at


what is with

WaitForExternalFile[command_, filename_String,
    pattern_:"*.txt"] := 
  Module[{i = 0, found = False},
    While[i++ < maxCount,
      (* look if the file is created *)
      found = MemberQ[FileNames[pattern], filename];
      If[found, Break[]];

and something like

WaitForExternalFile["EMFIELD.EXE -p1 -p2","Results.txt",10000]

should work.

Possibly you get a timing problem, when the program
has not finished the file but Mathematica try
to read from an open file.

The best way would be to write a MathLink program
that return the result to the kernel.


Roberto Brambilla wrote:
> Hi,
> I'd like to use Mathematica to run an extermal program,
> let me say EMFIELD.EXE with some parameters p1 , p2 :
> Run["EMFIELD.EXE -p1 -p2"]
> The external program put results in the ascii file Results.txt
> (a filename that I can change every time).
> Then I read results from it with
> ReadList["Results.txt", Number,...]
> After an analysis of them inside the same session of Mathematica,
> I modify the parameters p1, p2 and run again the external program.
> And so on for many times until analysis is OK.
> Since EMFIELD may take seconds or hours to generate the results,
> depending on the complexity of the problem and the values of parameters,
> how can I tell Mathematica to wait until the Results.txt file is
> created or updated? Pause[n] would be fine if I knew n, but this is
> not the case and putting a guessed large n is a poor solution
> (offending Mathematica lovers!).
> Many thanks, Roberto
> Roberto Brambilla
> Via Rubattino 54
> 20134 Milano
> tel +39.02.2125.5875
> fax +39.02.2125.5492
> rlbrambilla at

  • Prev by Date: Re: Re: Re: DSolve and N do not commute
  • Next by Date: Re: Time-consuming series coefficients
  • Previous by thread: Re: waiting command
  • Next by thread: Re: waiting command