capturing a call system() output into a variable 
Author Message
 capturing a call system() output into a variable

For my next impossible query... is it possible to
capture the output of a call system() into a
variable in fortran? Other than having the program
write to a file, and then read that file in the
Fortran program (after pausing long enough for
it to happen. Hmm., or does the calling program
wait for the system call to complete?).

Thanks!



Mon, 12 Sep 2011 07:07:57 GMT  
 capturing a call system() output into a variable

Quote:
>For my next impossible query... is it possible to
>capture the output of a call system() into a
>variable in Fortran? Other than having the program
>write to a file, and then read that file in the
>Fortran program (after pausing long enough for
>it to happen. Hmm., or does the calling program
>wait for the system call to complete?).

>Thanks!

try it.
SOme call wait, others don't (so I hear) - but if your
call still has the external file open, you will
probably get an error in open()- and maybe you just try
again until no error.
Chris


Mon, 12 Sep 2011 07:15:48 GMT  
 capturing a call system() output into a variable

Quote:

> For my next impossible query... is it possible to
> capture the output of a call system() into a
> variable in Fortran? Other than having the program
> write to a file,

In unix/C (but not in standard C) you can use
popen() to open a pipe to the stdout of a program,
and read that output.

FILE *in;
in=popen("dir","r");
while(fgets(buf,sizeof buf,in)>0) printf("%s",buf);

You might do it with C interoperability and a
C function to assign to your variable.  Not completely
portable, though.

Quote:
> and then read that file in the
> Fortran program (after pausing long enough for
> it to happen. Hmm., or does the calling program
> wait for the system call to complete?).

I believe, yes, it waits for the program to finish.

-- glen



Mon, 12 Sep 2011 07:32:11 GMT  
 capturing a call system() output into a variable

Quote:


> > ... call system()...
> > Hmm., or does the calling program
> > wait for the system call to complete?).

> I believe, yes, it waits for the program to finish.

Since it isn't part of the Fortran standard, one can't definitively say.
I believe that most current systems would do so, but I'm pretty sure I
have used some that didn't. That's just one of the numerous portability
questions involved, with different compilers providing simillar, but not
identical functionality.

--
Richard Maine
email: last name at domain . net
domain: summer-triangle



Mon, 12 Sep 2011 07:40:44 GMT  
 capturing a call system() output into a variable
(snip regarding system)

Quote:

> Since it isn't part of the Fortran standard, one can't definitively say.
> I believe that most current systems would do so, but I'm pretty sure I
> have used some that didn't. That's just one of the numerous portability
> questions involved, with different compilers providing simillar, but not
> identical functionality.

I did mention that popen() wasn't standard, but I didn't
say that about system().

With unix, either the shell or the program run from
the shell could background (or detach) , in which case
system() would be expected to return.  Other systems
have similar functionality.  

But yes, you never know when using non-standard calls.

-- glen



Mon, 12 Sep 2011 07:50:44 GMT  
 capturing a call system() output into a variable
In Dread Ink, the Grave Hand of glen herrmannsfeldt Did Inscribe:

Quote:

>> For my next impossible query... is it possible to
>> capture the output of a call system() into a
>> variable in Fortran? Other than having the program
>> write to a file,

> In unix/C (but not in standard C) you can use
> popen() to open a pipe to the stdout of a program,
> and read that output.

> FILE *in;
> in=popen("dir","r");
> while(fgets(buf,sizeof buf,in)>0) printf("%s",buf);

> You might do it with C interoperability and a
> C function to assign to your variable.  Not completely
> portable, though.

I think Glen's is thinking along the same lines as I here.  I was thinking
of doing it with dos as opposed to C.

Quote:

>> and then read that file in the
>> Fortran program (after pausing long enough for
>> it to happen. Hmm., or does the calling program
>> wait for the system call to complete?).

> I believe, yes, it waits for the program to finish.

> -- glen

You'll know what happens on windows.  The trick is not to hurt yourself on
less popular OS's.

There's a really good dos group on usenet if you're interested.
--
Frank

Oh, What Doesn't Kill You Can Have Lingering Aftereffects!
~~ Al Franken,



Mon, 12 Sep 2011 12:13:03 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Capturing System Command Output (was: SH Backquote)

2. Capturing System Command Output (was: SH Backquote)

3. Capturing System Command Output

4. Capturing output from Kernel#system

5. capturing output of os.system() into a list?

6. capture 'system' output

7. capturing output from os.system() in Windows?

8. capturing the output from a called program

9. HOW TO CAPTURE AN OUTPUT LINE OF A VHDL OUTPUT IN TCL

10. Output variables and current system date on same line

11. need output from system im variable

12. Retrieve output from system call

 

 
Powered by phpBB® Forum Software