Run commands on externally running process

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.

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:

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 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).

You can do

write(proc, command)

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