# IOBuffer a Matrix?

**URL:** <https://discourse.julialang.org/t/iobuffer-a-matrix/60913>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 10, 2021, 8:28pm UTC](https://discourse.julialang.org/t/iobuffer-a-matrix/60913 "2021-05-10T20:28:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [May 10, 2021, 8:28pm UTC](https://discourse.julialang.org/t/iobuffer-a-matrix/60913/1 "2021-05-10T20:28:45Z")

</div>

Hi All!  
I am making a pseudo wrapper for a Fortran code. I just need to parse a matrix as an input to it.

In the terminal i can do:

`cat data | ./Perplex_LitMod_T`

Where data looks like this:

```julia
   3 0 0 0
1500 65000 5 0
1500 65000 5 0
1500 65000 5 0

```

The first line is just the count of lines (followed by zeros) and then the data that the code reads.

I was trying to call the code from Julia like this:

> readchomp(pipeline(IOBuffer(“$DATA”), `./Perplex_LitMod_T`)))

But it is not working. Error massage:

```julia
At line 65 of file Perplex_LitMod_T.for (unit = 5, file = 'stdin')
Fortran runtime error: Bad integer for item 1 in list input

Error termination. Backtrace:
#0 0x16115bebd
#1 0x16115cb75
#2 0x16115d76b
#3 0x161381008
#4 0x161385019
#5 0x161385bd2
#6 0x102c3e2f5
#7 0x102c9ad7e
ERROR: failed process: Process(`./Perplex_LitMod_T`, ProcessExited(2)) [2]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:525 [inlined]
 [2] read(cmd::Base.CmdRedirect)
   @ Base ./process.jl:412
 [3] read(cmd::Base.CmdRedirect, #unused#::Type{String})
   @ Base ./process.jl:421
 [4] readchomp(x::Base.CmdRedirect)
   @ Base ./io.jl:923
 [5] top-level scope
   @ none:1

```

Any ideas how to parse a matrix through Julia?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 10, 2021, 10:57pm UTC](https://discourse.julialang.org/t/iobuffer-a-matrix/60913/2 "2021-05-10T22:57:09Z")

</div>

I think you want the `stdin` keyword? e.g.

```julia
julia> readchomp(pipeline(`sort`, stdin=IOBuffer("foo\nbar\nbaz")))
"bar\nbaz\nfoo"

```

That being said, you’d probably be better off compiling your Fortran code into a shared library and calling a subroutine via `ccall` than piping data in and out as text.
