How to redirect Julia function's output to external file

689 views
Skip to first unread message

WANG

unread,
Mar 16, 2013, 2:17:27 AM3/16/13
to julia...@googlegroups.com
Is there a way to redirect Julia function's out put to external file?

For example , redirect `sqrt(5)` to "out.txt" within REPL.

Jason Knight

unread,
Mar 16, 2013, 6:10:13 PM3/16/13
to julia...@googlegroups.com
There's currently no way to modify the Julia's STDOUT descriptor dynamically (there was a mailing list thread about this somewhere, although I don't think this even makes sense inside the REPL), but you can always save the output of any command to a file:

  run(`echo $(sqrt(5))` > "/tmp/tmp")

or the slightly uglier,

  open(fid->write(fid,"$(sqrt(5))\n"), "/tmp/tmp", "w")

WANG

unread,
Mar 17, 2013, 8:48:41 AM3/17/13
to julia...@googlegroups.com
Thanks. The second one is of more help because I'm using a Windows binary.

However, I think this feature would be useful when you write a pure function. This feature could redirect result to files quite simply.

在 2013年3月17日星期日UTC+8上午6时10分13秒,Jason Knight写道:
Reply all
Reply to author
Forward
0 new messages