# Tag Info

12

I am not sure that this is possible. The $Output and$Messages variables hold the output stream to where the standard output (and the message output) from the kernel goes. If you check these, you'll see that they're simply set to stdout. If you remove ReadProtected from NotebookWrite, you'll see that it is passing data to the front end instead of writing ...

11

You could use RunScheduledTask or its relatives for this. For example, to append a random integer to catch once every two seconds you could do something like catch = {}; task = RunScheduledTask[AppendTo[catch, RandomInteger[10]], 2]; You could also use CreateScheduledTask which is similar to RunScheduledTask except that the task won't be started ...

9

File Output Use an output stream. s = OpenWrite["your_filename"]; Dynamic[With[{a = ImageKeypoints[EdgeDetect[CurrentImage[], 30], "PixelPosition"]}, Write[s, a]; a], Deinitialization :> Close[s]] It will close the stream upon the deletion of the dynamic cell. It is not a bad idea to put time stamp with it. Dynamic[With[{a = ...

7

What happend to ABC? Input Streams "read ahead" and buffer data from their sources. When you write rtmp = OpenRead["tmp"], OpenRead reads the whole file "tmp" into memory. This is called buffering. (It reads up to 16 kilobytes, but your file's not that large.) All subsequent operations on the rtmp stream are really just operating on pre-loaded data in ...

7

Try this: stream = StringToStream[ "Apple,Jack,1,123.456\nOrange,Jill,2,456.789\n"]; While[! EndOfFile === (data = Read[stream, {Word, Word, Character, Number, Character, Number}, WordSeparators -> ","]), Print["Fruit:", data[[1]], " Name:", data[[2]], " Integer:", data[[4]], " Real:", data[[6]]];] Having learnd something from ...

6

This seems to work and doesn't require conversion stream = StringToStream[ "Apple,Jack,1,123.456\nOrange,Jill,2,456.789\n"]; While[! EndOfFile === (data = Read[stream, Riffle[{Word, Word, Number, Number}, Word], TokenWords -> {","}] /. {"," -> Sequence[]}), Print["Fruit:", data[[1]], " Name:", data[[2]], " Integer:", ...

6

Here is a function which may help: Clear[readRows]; readRows[stream_, n_] := With[{str = ReadList[stream, "String", n]}, ImportString[StringJoin[Riffle[str, "\n"]], "Table"] /; str =!= {}]; readRows[__] := $Failed; I tested on your file and it works all right (it may make sense to read rows in batches, this is much faster): n=0; str = ... 6 According to the docs, both Write and WriteString should accept an "output channel," which is just a list of streams. On my system (v.8 on MacOS), Write behaves the same way as on your system when outputting anything, but WriteString behaves as expected. Similarly, this Write[{tex1, tex2}, 3, 4]; also misbehaves in the same manner. So, the issue isn't ... 6 Are you on a Windows machine? If so, try OpenReading the file with BinaryFormat->True. When you open a file on a Windows machine in "text mode," with BinaryFormat->False (which is the default), the system has to translate the Windows newline sequence \r\n (two bytes which mark the end of the line) into the single \n character. In the C language and ... 5 Streams and iterators Using streams would certainly be one of the most elegant ways to do this. In any case, you will at least need an iterator for your sequence of numbers. The reason why an abstraction of an iterator is useful is because it separates the iteration over your sequence from the stuff you want to do with individual elements, so that you can ... 5 pixpos = {}; Dynamic[ a = EdgeDetect[CurrentImage[], 30]; b = ImageKeypoints[a, "PixelPosition"]; AppendTo[pixpos, b]; a] Let it run for some time then delete the graphic to stop the Dynamic and plot them to show we indeed collected the results: Graphics@Table[{Hue[Random[]], Line[i]}, {i, pixpos}] 5 Export["test.txt", {a}] works for me "Plaintext" is already the default output form of Export. The { } around a prevents Export from seeing it as a series of arguments (a is a list in your example) that each have to be put on its own line. 5 Here is a string processing way of extracting the "x-axis" data from the XPM file that you gave. I'll assume that you have already imported the all of the file's records into the string text - e.g. using text = Import[filename,"String"], though I haven't tested this as I actually copied (then pasted into an empty string) the contents of the XPM file quoted ... 5 Here is a letter I got regarding this question from premier service technical support: Thank you for taking the time to send this in. Unfortunately, I do not believe this functionality currently exists in Mathematica and I have forwarded the suggestion that it be included in a future release of Mathematica to the developers in charge of this area. ... 4 I can only give a partial answer. Your problem arises because FilePrint doesn't use$Output (stdout). It uses the stderr stream, so you can't capture what it writes by using Block and assigning to $Output. Unfortunately, I don't think any system variable is bound to stderr. Perhaps I'm wrong. In that case, I hope a more knowable person will be able to ... 4 Since PrintTemporary does not use output streams, but rather is akin to CellPrint, I believe you will need to add this functionality manually. For example: Unprotect[PrintTemporary];$log = OpenAppend["logfile.txt"]; PrintTemporary[expr_] /; ! TrueQ[ptLog] := Block[{ptLog = True}, WriteString[$log, expr]; PrintTemporary @ expr ] ... 4 OpenWrite returns the stream it opens, so do this str = OpenWrite["~/example"] OutputStream["/Users/oldmg/example", 83] Close[str] Also, all streams have a name. In this case it is "/Users/oldmg/example". 3 Your problem is with not reassigning$Output back to stdout. You could do it by writing your code like so: fname = FileNameJoin[{HomeDirectory[], "Desktop", "test.txt"}]; Module[{out = $Output},$Output = OpenWrite[fname, FormatType -> OutputForm]; Write[$Output, "The quick brown fox ..."]; Print[$Output]; Close[$Output];$Output = out] The ...

3

You can stay with Put using the method I showed here for PutAppend: SetOptions[OpenWrite, PageWidth -> Infinity]; a >> tmp This method is especially useful in the case of PutAppend because it allows you to maintain a running log file with results of intermediate computations with one expression per line.

3

Try using Export and Import. Make sure to include "Data" as the second argument of Import. SetDirectory[$TemporaryDirectory]; Export["myfile.txt", a] in = Import["myfile.txt", "Data"] If you really want to see the Greek letters spelled out you can then use FullForm[in] but this will also return List[] instead of {}. 3 I expected this to work but it apparently only writes Print output: AppendTo[$Output, OpenWrite["out.txt", FormatType -> OutputForm] ] A workaround using $PrePrint: output = OpenWrite["out.txt", FormatType -> OutputForm];$PrePrint = (Write[output, #]; #) &;

2

The basic idea is to install a virtual MIDI device software on your Mac and change the system default MIDI output to that virtual device. Mathematica will play into it, and the device can at the same time function as a MIDI input for Logic/GarageBand. http://www.johanlooijenga.com/tools/5-apps/12-virtual-ports.html It would be easier if you could change ...

1

The simplest, most general way to do this is probably via Streams[]. Set up some data ... test = StringTake[ExampleData[{"Text", "DeclarationOfIndependence"}], 50] (* sample data ... *); str = StringToStream[#] & /@ StringSplit[test]; (* converted to streams *) Now the example ... Streams[] (* all streams *) ostr = Select[Streams[], ...

1

This seems to work. I think this sort of thing is probably dangerous -- well, unreliable. file = DataPacletsGetDataPacletResource["CountryData", "CountryData.wdx"]; DataPacletsCountryDataDump`\$StreamCache["CountryData"] = OpenRead[file, BinaryFormat -> True] I don't have webMathematica, so I can't test it on that.

1

It looks like you only need a looping construct that terminates when the first True is encountered with the Or operation. So how about this: f = PrimeQ (* ==> PrimeQ *) notFound = False; n = 0; While[! notFound, n += 1; notFound = notFound || f[n] ]; n (* ==> 2 *)

Only top voted, non community-wiki answers of a minimum length are eligible