I'm running a bash script inside of a Python script, and I need to use the variables that were defined inside of the bash script, in the Python script.
For some context, here is the bash script:
#!/bin/bash
updates=$(/usr/lib/update-notifier/apt-check 2>&1)
all=${updates%";"*}
security=${updates#*";"}
Here is how I am calling it in the Python script:
import subprocess
subprocess.call(["/usr/bin/checkupdates"])
I want to use the variables that were defined in that bash script ('all' and 'security') in this SQL update statement (which is part of the Python script):
cursor.execute("update dbo.updates_preprod set updates_available = ?, securityupdates_available = ? where hostname = ?",(all, security , socket.gethostname()))
cnxn.commit()
Is it possible to do this? If not, could I run 2 separate scripts (each script would echo one of the variables) and grab the stdout of each script and define it as a variable in Python?
Thanks in advance!
In the end it was much easier to call that command directly from the Python script.
output = subprocess.check_output("usr/lib/update-notifier/apt-check", shell=True) all,sec = output.decode().split(';')
Thanks to @cdarke and @furas for the suggestion.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.