# Run commands on externally running process

**URL:** <https://discourse.julialang.org/t/run-commands-on-externally-running-process/85026>\
**Category:** General Usage\
**Tags:** pipelines, external-process\
**Created:** [July 30, 2022, 11:53am UTC](https://discourse.julialang.org/t/run-commands-on-externally-running-process/85026 "2022-07-30T11:53:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![s-baumann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/s-baumann/32/5843_2.png) [@s-baumann](https://discourse.julialang.org/u/s-baumann)\
**Post date:** [July 30, 2022, 11:53am UTC](https://discourse.julialang.org/t/run-commands-on-externally-running-process/85026/1 "2022-07-30T11:53:18Z")

</div>

I want to run one command to open a program. Then do a second command in this program.  
For instance in the below case the first line opens a psql session and the second should insert some data via a csv file.

```julia
line1 = `$LOCAL_POSTGRES_INSTALLATION -h $HOST -U $DATABASE_USER -d $DBNAME -p $PORT`
line2= ` \\COPY $schema_name.$table_name \( $DATABASE_COLUMNS \) FROM $FILENAME csv header \; `

```

I am struggling to do this via a pipeline. The best I have got is:

```julia
pstdin = Pipe()
pstdout = Pipe()
pstderr = Pipe()
proc = run(pipeline(line1,
                    stdin = pstdin, stdout = pstdout, stderr = pstderr),
                    wait = false)

```

If you run `process_running(proc)` it seems like I have a process running psql. But I am not sure how to then send each command to this running process.

Any ideas how to do this?

The [documentation](https://docs.julialang.org/en/v1/manual/running-external-programs/) suggests something like:  
`run(pipeline(line1 , line2));`  
should send each command in turn but this did not work for me (I guess as second command is run in program started by the first).

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [July 30, 2022, 2:00pm UTC](https://discourse.julialang.org/t/run-commands-on-externally-running-process/85026/2 "2022-07-30T14:00:33Z")

</div>

You can do

```julia
write(proc, command)

```

where `command` is a string. This will send the string to the process’ standard input.
