# How can i pipe arbitrary strings into a temporary file pipe for programs that read from a file?

**URL:** https://discourse.julialang.org/t/how-can-i-pipe-arbitrary-strings-into-a-temporary-file-pipe-for-programs-that-read-from-a-file/37695
**Category:** General Usage
**Tags:** question
**Created:** [April 16, 2020, 1:00pm UTC](https://discourse.julialang.org/t/how-can-i-pipe-arbitrary-strings-into-a-temporary-file-pipe-for-programs-that-read-from-a-file/37695 "2020-04-16T13:00:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![NHDaly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhdaly/32/1413_2.png) [@NHDaly](https://discourse.julialang.org/u/NHDaly)
#### Post date: [April 16, 2020, 1:00pm UTC](https://discourse.julialang.org/t/how-can-i-pipe-arbitrary-strings-into-a-temporary-file-pipe-for-programs-that-read-from-a-file/37695/1 "2020-04-16T13:00:03Z")

</div>

What is the julia pipeline equivalent to bash’s process substitution?  
[https://unix.stackexchange.com/a/64011/43398](https://unix.stackexchange.com/a/64011/43398)

And/or can we use `Pipe()` to make a Named Pipe?  
[https://unix.stackexchange.com/questions/63923/pseudo-files-for-temporary-data](https://unix.stackexchange.com/questions/63923/pseudo-files-for-temporary-data)

Or is there some other, more julian way to pipe arbitrary strings from julia into a process that expects a filename as an argument?

For example, the `diff` process expects its arguments to be filenames. But if i want to diff two strings, in bash I can use process substitution to do it:

```bash
$ diff --unified <(echo "hello 1") <(echo "hello 2")
--- /dev/fd/11 2020-04-16 08:59:01.000000000 -0400
+++ /dev/fd/12 2020-04-16 08:59:01.000000000 -0400
@@ -1 +1 @@
-hello 1
+hello 2

```

How could i call `diff` with temporary pipes built from strings in julia?  
🙂 Thanks!

---

<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: [April 16, 2020, 1:28pm UTC](https://discourse.julialang.org/t/how-can-i-pipe-arbitrary-strings-into-a-temporary-file-pipe-for-programs-that-read-from-a-file/37695/2 "2020-04-16T13:28:31Z")

</div>

You can pipe arbitrary strings as `stdin` via `pipeline`:

```julia
julia> pipeline(`sort`, stdin=IOBuffer("cat\nbarn\napple\n"))
pipeline(`sort`, stdin<IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=15, maxsize=Inf, ptr=1, mark=-1))

```

I don’t think there is a high-level analogue for process substitution for arbitrary files arguments, though. You could [implement it based on the `bash` algorithm](https://en.wikipedia.org/wiki/Process_substitution#Mechanism) I guess.

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [April 16, 2020, 1:32pm UTC](https://discourse.julialang.org/t/how-can-i-pipe-arbitrary-strings-into-a-temporary-file-pipe-for-programs-that-read-from-a-file/37695/3 "2020-04-16T13:32:20Z")

</div>

There really isn’t a generic way. Julia is not a shell prompt (and you seem to want Julia to match bash in it’s abilities) and worse Julia runs on Windows and Linux. So that makes it doubly hard to implement something generic.

If you are willing to tie yourself to Linux you could look at `mkfifo` either the command or the library call, call that twice to create two named pipes. Then you would need to spawn a 2 tasks to write to the files. Then you could pass both those named pipes to whatever command you want to run.

---

<div class="post-metadata">

### Author: ![NHDaly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhdaly/32/1413_2.png) [@NHDaly](https://discourse.julialang.org/u/NHDaly)
#### Post date: [April 17, 2020, 4:55pm UTC](https://discourse.julialang.org/t/how-can-i-pipe-arbitrary-strings-into-a-temporary-file-pipe-for-programs-that-read-from-a-file/37695/4 "2020-04-17T16:55:20Z")

</div>

Thanks both for the answers! 🙂

I ended up just creating a temporary file, writing to the temp file, and passing that, which is in a lot of ways quite similar to a temporary file pipe anyway.

```julia
    mktemp() do f, io
        out, _ = mktemp()
        write(io, str)
        close(io)
        run(`cobc -free -b -o $out $f`)
        return Libdl.dlopen(out)
    end

```
