# Run a subprocess in a pseudo terminal

**URL:** <https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294>\
**Category:** General Usage\
**Created:** [February 24, 2018, 12:07pm UTC](https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294 "2018-02-24T12:07:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Post date:** [February 24, 2018, 12:07pm UTC](https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294/1 "2018-02-24T12:07:28Z")

</div>

I am trying to build a small script which would initiate workers on PBS cluster through interactive job. For that I need a way to execute `cat $PBS_NODEFILE` in interactive session to get associated resources to me. Essentially what I would like to accomplish is something like this:

```julia-auto
output, input, p = readandwrite(`qsub -I`)
readline(output) # waiting for job to start
write(input,"cat \$PBS_NODEFILE \n")
# Reading given resources

# Starting julia workers with my custom needs

# Doing some calculation

# Killing interactive session and so the job
kill(p,9)

```

But I get an error after executing `readandwrite(`qsub -I`)`:

```julia-auto
qsub: standard input and output must be a terminal for interactive job submission

```

How could I get around that?

# EDIT

I am looking for similar behavior what [ptyprocess](https://github.com/pexpect/ptyprocess) offers.

---

<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:** [February 24, 2018, 1:52pm UTC](https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294/2 "2018-02-24T13:52:27Z")

</div>

See [https://github.com/JuliaParallel/ClusterManagers.jl](https://github.com/JuliaParallel/ClusterManagers.jl) for PBS support.

(Note that it uses some [command-line options to `qsub`](https://github.com/JuliaParallel/ClusterManagers.jl/blob/0febec6cb62683efff9489e0e2df2bf03da746b4/src/qsub.jl) to run it in batch mode. Hopefully you won’t need to run `qsub` directly and can use ClusterManagers instead.)

---

<div class="post-metadata">

**Author:** ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Post date:** [February 24, 2018, 3:07pm UTC](https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294/3 "2018-02-24T15:07:47Z")

</div>

ClusterManagers works fine and I have been using it extensively . However it does not allow to specify how workers should be initiated. For example, I would like to have a one worker per node for making BLAS faster with threading.

---

<div class="post-metadata">

**Author:** ![John\_Hearns](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_hearns/32/1685_2.png) [@John\_Hearns](https://discourse.julialang.org/u/John_Hearns)\
**Post date:** [February 25, 2018, 10:25am UTC](https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294/4 "2018-02-25T10:25:18Z")

</div>

Janis, I manage a PBS cluster. I think that the qsub behaviour for interactive jobs is correct. I think you understand that also.  
I will log in and see if we can make a construct which behaves like ptyprocess though.

---

<div class="post-metadata">

**Author:** ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Post date:** [February 25, 2018, 12:45pm UTC](https://discourse.julialang.org/t/run-a-subprocess-in-a-pseudo-terminal/9294/5 "2018-02-25T12:45:58Z")

</div>

Thanks. However I have changed my mind on how I could approach this problem, I found that I can actually establish ssh connection with main node when I run submitted job. Some ideas are running in my mind how to use that.

But perhaps the simplest solution is to submit a job which creates a machinefile and exits when that file is deleted.
