0

I'm making a Python script that automates some tasks in Linux. The script installs some packages and, after the installation of this pacakges, i want the user to run some terminal commands. I was wondering if there is a way for do this by "Pausing" the script and by creating a direct comunication between the terminal and the user.

I know that there are other ways for do that like by writing an input statement in python and make an os call that run what the user typed like this

from python import os

cmd = input('Type your command here: ')
os.system(cmd)

or by using some subrocess functions in the same way

import subprocess

cmd = input('Type your command here: ')
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, errors = p.communicate()

But there is a way for create a comunication between the terminal and the user while the script is running without the necessity to open a new terminal?

2
  • Why do you want to get input from the terminal instead of getting the input through input() function? Commented Jun 17, 2019 at 8:38
  • Just for know is possible to do in that way Commented Jun 17, 2019 at 8:40

1 Answer 1

2

You can just start a shell session:

os.system('/bin/sh')
Sign up to request clarification or add additional context in comments.

1 Comment

brilliant. @Mat.C this is your solution. to go back to the script just exit this new shell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.