donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Two Scripts

Sun Apr 24, 2016 3:53 pm

I have a Python script with a menu. At one selection, I want to start or call another script but it's BASH. The result is put in a text file in /tmp.
I want to do this:
Start Python script. At menu selection, have it start the BASH script. At end return back to Python script which processes the file in /tmp.
Is this possible? How would I do it?

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Two Scripts

Sun Apr 24, 2016 4:32 pm

Use the subprocess module :

https://docs.python.org/2/library/subprocess.html

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Re: Two Scripts

Sun Apr 24, 2016 5:58 pm

ghans wrote:Use the subprocess module :

https://docs.python.org/2/library/subprocess.html

ghans
Really new in Python, looked at the site, don't know what to look for.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Two Scripts

Sun Apr 24, 2016 5:59 pm

Code: Select all

import subprocess
subprocess.call("COMMAND TO RUN", shell=True)
There are 10 types of people: those who understand binary and those who don't.

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Two Scripts

Mon Apr 25, 2016 7:31 pm

What is the advantage of using sub process over system call with os.system"command")?
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Two Scripts

Mon Apr 25, 2016 8:31 pm

liudr wrote:What is the advantage of using sub process over system call with os.system"command")?
More control and more options.
See https://docs.python.org/2/library/os.html#os.system
https://docs.python.org/2/library/subpr ... placements

Return to “Python”