v.sheg
v.sheg

Reputation: 53

Run shell from Python and make it active

I use Python scripts to prepare some stuff for long quantum calculations. So, when I run target binary from terminal

targetbin file.inp > file.out

I can see that process is still running. With Python I do some automations:

#!/usr/bin/env python3

# blah blah blah

cmd = ' '.join([targetbin, modified_inp_file, some_options, '>', created_out_file])
# /usr/bin/targetbin /tmp/XXX.inp -a 1 -b 2 -c 3 > file.out

subprocess.Popen(cmd, shell=True)

run it from terminal:

pythonscript -x 1 -y 2 -z 3 file.inp

and it works fine, but it doesn't hold shell. After Python initiate the process I want to delegate it completely to the shell and then exit Python itself, as if I entered cmd myself. Is it possible?

Upvotes: 2

Views: 139

Answers (1)

zvi
zvi

Reputation: 4706

You can try this way -

  1. Run a shell script that run the python script.
  2. Python will do the automations and will run the the process run by POPEN.
  3. Shell script will do fg. (Alternatively, you can get the PID from python and run kill -CONT <pid>).

Upvotes: 1

Related Questions