1

I have a Python script which runs terminal commands to complete tasks. At one point in the script, I start a wifi network and everything sets up just fine, but the terminal will leave a blinking cursor and not accept any further commands (as the wifi command remains running). I may type other commands and hit enter, but nothing will happen. The only way to continue my script is to hit Ctrl+Z to stop the wifi command. This then allows the script to continue to run without any issues.

Is there a way to open a new process or terminal window to run a specific terminal command so that I may continue to run commands from Python on a main window?

EXTRA ANSWER: You can use something called threading in python. This will let you run commands and functions separately while continuing the main script.

  • You should post your script so we can help you. – Ravexina May 20 '17 at 17:32
  • 2
    When you hit Ctrl-Z, you get back to command prompt and the program is paused. Type "bg" and the program will continue to run in background. When you type "fg", you will bring it in foreground again. If you have more programs in background type "jobs" to see them. Then you can use number as parameter of fg to bring selected program in foreground. – nobody May 20 '17 at 17:39
  • 2
    add a & at the end of the command. – Rinzwind May 20 '17 at 17:39
  • 1
    Really this is a programming question rather than an Ubuntu question - I think what you want is subprocess.Popen rather than subprocess.call - the former is non-blocking. See for example What's the difference between subprocess Popen and call (how can I use them)?. – steeldriver May 21 '17 at 2:12
1

If the script (yes post it) doesn't need user action, you could start it in the background by appending & to the command:

start_the_wifi &

or, follow your Ctrl-Z with bg to put it in the background.

Read man bash, the Job Control section in particular.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.