[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem calling an external program (Gretl) multiple times.
From: |
Jaroslav Hajek |
Subject: |
Re: Problem calling an external program (Gretl) multiple times. |
Date: |
Thu, 4 Feb 2010 07:56:48 +0100 |
On Thu, Feb 4, 2010 at 12:42 AM, Werner <address@hidden> wrote:
> I am writing code which generates data, and then calls an external program
> (Gretl) to analyse that data and pass back its output which is then saved.
> The problem is that while the first call behaves as I would expect with all
> the data being produced the subsequent call gets stuck somewhere. That is to
> say the commands passed to Gretl are not all executed (beginning with the
> first line) so that when the subsequent output is passed back it contains
> none of the data that I want. My code is as follows:
>
> -----------------------------------------------------------------------------------------------------------
> for i=1:1:NumQus
>
> ## Generate Gretl script
> GretlScript = [sprintf("%s%s%s","open ", DataDirect, DataFileName);"setobs
> 12 1990:01 --time-series";"ols Y const X1 X2";"modtest 12 --autocorr"];
>
> ## Run gretl script and get output
> GretlOutput = rungretlcode(GretlScript);
>
> ## Save GretlOutput
>
> end
>
> ---------------------------------------------------------------------------------------------------------
>
> function GretlOutput = rungretlcode(GretlCode)
>
> [in,out,pid] = popen2("gretlcli","");
> sleep (0.5);
>
> for i=1:size(GretlCode,1)
> fputs(in,sprintf("%s%s",GretlCode(i,:),"\n"));
> end
>
> GretlOutput = readstream(out);
>
> fclose(in);
> fclose(out);
>
> end
>
> --------------------------------------------------------------------------------------------------------------
>
> I know that on the second iteration the command is being passed correctly,
> but it doesn't seem that Gretl is executing it for some reason.
>
> I am using GNU Octave, version 3.0.5 and Gretl version 1.8.1 on Ubuntu
> (Karmic Koala).
>
> On a side note, in my function rungretlcode I give a pause to allow gretl to
> open. Is there any way to check the system whether gretl is open and then
> begin execution rather than some arbitrary pause.
>
> Thanks for you help in advance.
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>
Please go back to the answer you got from me 8 days ago, and read
carefully the second sentence, word by word:
"Don't forget to flush commands after they're written."
help fflush
regards
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz