fprintf doesn't write "hello" to temporary file

View: New views
4 Messages — Rating Filter:   Alert me  

Parent Message unknown fprintf doesn't write "hello" to temporary file

by Aditya Bhagwat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

fileName = sprintf('%s.sh', tmpnam());
fid = fopen(fileName, "w");
fprintf(fid, "hello\n");
fclose(fid);
cat(fileName)

For some reason the file remains empty and no "hello" is present in it.
Any idea what is happening here?

Regards and many thanks for your help,

Aditya



> Send Help-octave mailing list submissions to
> help-octave@...
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> or, via email, send a message with subject or body 'help' to
> help-octave-request@...
>
> You can reach the person managing the list at
> help-octave-owner@...
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Help-octave digest..."
>
>
> Today's Topics:
>
>    1. Installing packages "java" and "jhandles" (Yuri Belenky)
>    2. Re: enabling immediate output behavior (Aditya Bhagwat)
>    3. parcellfun example code snippet? (Michael Creel)
>    4. Re: enabling immediate output behavior (Francesco Potort?)
>    5. plot titles are off of the plot (charles reid)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 23 Oct 2009 07:46:23 +0200
> From: Yuri Belenky <yuri.belenky@...>
> Subject: Installing packages "java" and "jhandles"
> To: help-octave@...
> Message-ID:
> <dbc892f60910222246l2f9b0973t9f2751393bd05fbe@...>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Trying to install packages "java" and "jhandles" on top of Octave 3.2.2
> running under Windows XP with no success. The Java SDK installed in
> directory "C:\Program Files\Java\jdk1.6.0_16" so I've set respective
> "JAVA_HOME" environment. Also set "JAVA_INCS" variable as "-IC:/Program
> \Files/Java/jdk1.6.0_16/include -IC:/Program
> \Files/Java/jdk1.6.0_16/include/win32" as recommended in some forums. The
> Octave is in "C:\Octave\...". When running "pkg install" command compiler
> reports that Java development kit cannot be found.
> Help is appreciated.
> Yuri
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20091023/d6d29fc2/attachment-0001.html 
>
> ------------------------------
>
> Message: 2
> Date: Fri, 23 Oct 2009 09:25:37 +0200
> From: Aditya Bhagwat <aditya@...>
> Subject: Re: enabling immediate output behavior
> To: Francesco Potort? <Potorti@...>
> Cc: help-octave@...
> Message-ID: <4AE15A71.1060706@...>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> Dear Francesco,
>
> Thanks for your involvement.
>  
>>> Thanks for your help. Even while using disp(a) as you suggested, in the
>>> Emacs editor's inferior octave process, all output is kept till the last
>>> function evaluation has been performed, and only then sent to the
>>> screen.
>>>    
>>>      
>> Hm.  I run octave as an Emacs inferior process, though in a different
>> op.sys. (Debian).  If I run this:
>>
>> octave> for i=1:50000 i=i+1; if (mod(i,10000)==0) disp(i); endif; endfor
>>
>> I get this:
>>
>>  10000
>>  20000
>>  30000
>>  40000
>>  50000
>> octave>
>>
>> where the lines are printed at intervals of about one second's time.
>> Would you try my example above and let us know what happens?
>>  
>>    
>
> In my case, for a couple of seconds, nothing happens. Then, the lines
> are printed all at once in the inferior octave window. I am working on
> emacs 23.1, which I compiled on Ubuntu 9.04.
>
> Regards,
>
> Aditya
>
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 23 Oct 2009 10:00:12 +0200
> From: Michael Creel <michael.creel@...>
> Subject: parcellfun example code snippet?
> To: help <help@...>
> Message-ID:
> <c8f260e70910230100sa1d56d7ld2ce25afe802aecf@...>
> Content-Type: text/plain; charset=ISO-8859-1
>
> I have been trying out parcellfun on 3.0.1 and 3.3.50+ and I'm not
> having luck. For example, if I try
> [a b] = parcellfun(2, @sin, {1}, {2}) I expect that a and b should
> hold sin(a) and sin(b). However, they are empty. So a working snippet
> would be welcome to see how this is supposed to go.
> Thanks, Michael
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 23 Oct 2009 13:24:36 +0200
> From: Francesco Potort? <Potorti@...>
> Subject: Re: enabling immediate output behavior
> To: Aditya Bhagwat <aditya@...>
> Cc: help-octave@...
> Message-ID: <E1N1IG4-0005E6-Gt@...>
> Content-Type: text/plain; charset=utf-8
>
>  
>> In my case, for a couple of seconds, nothing happens. Then, the lines
>> are printed all at once in the inferior octave window. I am working on
>> emacs 23.1, which I compiled on Ubuntu 9.04.
>>    
>
> Allright, try this:
>
> octave> more off
> octave> for i=1:20000 i=i+1; if (mod(i,4000)==0) disp(i); endif; endfor
>
> And look at what happens
>
>  

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: fprintf doesn't write "hello" to temporary file

by Aditya Bhagwat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,
> fileName = sprintf('%s.sh', tmpnam());
> fid = fopen(fileName, "w");
> fprintf(fid, "hello\n");
> fclose(fid);
> cat(fileName)
>
> For some reason the file remains empty and no "hello" is present in
> it. Any idea what is happening here?

I should add that I am working on octave 3.2.3, compiled on Ubuntu 9.04.
I am calling octave from within emacs 23.1.

Regards and many thanks for your help,

Aditya



_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: fprintf doesn't write "hello" to temporary file

by Aditya Bhagwat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

>> fileName = sprintf('%s.sh', tmpnam());
>> fid = fopen(fileName, "w");
>> fprintf(fid, "hello\n");
>> fclose(fid);
>> cat(fileName)
>>
>> For some reason the file remains empty and no "hello" is present in
>> it. Any idea what is happening here?
>
> I should add that I am working on octave 3.2.3, compiled on Ubuntu
> 9.04. I am calling octave from within emacs 23.1.
I found the problem. The code is actually working, I only shouldn't be
using the 'cat' function. The cat function is meant to concatenate
vectors in octave, I mistakenly took it for the linux cat function to
display the contents of a file.

Regards,

Aditya
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: fprintf doesn't write "hello" to temporary file

by Przemek Klosowski-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/23/2009 09:56 AM, Aditya Bhagwat wrote:
> Dear all,
>> fileName = sprintf('%s.sh', tmpnam());
>> fid = fopen(fileName, "w");
>> fprintf(fid, "hello\n");
>> fclose(fid);

Good so far...

>> cat(fileName)

.. but here you have a wrong cat. Check out Octave's help: 'help cat'
reveals that this is its array concatenation function, not the
filesystem 'cat' command. Try one of those:

system(sprintf('cat %s',fileName))

system(['cat ' fileName])
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave