0

I would like to know how can i use my variables in output of another command. For example if i try to generate some keys with "openssl" i'll get the question about the country, state, organizations etc.

I would like to use my variables in the script that i have to fill this information. I'll have variable "Country"; variable "State" etc. and to be parsed/set in to this questions from the openssl command when is executed.

I'm trying this in bash but also would like to know how will be the same think done in python.

Kind regards

1 Answer 1

1

You have multiple ways to do so. 1. If you have your script launched before the python script and the result set in an enviroment variable you can read the environment variable from your python script as follows:

import os 
os.environ.get('MYVARIABLE', 'Default val')

Otherwise you can try to launch the other application from your python script and read the result by using os.popen():

import os
tmp = os.popen("ls").read()

or better (if you have a python newer than 2.6)

import subprocess
proc = subprocess.Popen('ls', stdout=subprocess.PIPE)
tmp = proc.stdout.read()
Sign up to request clarification or add additional context in comments.

4 Comments

and what about Bash ? Also the other command is openssl and what i want to achieve is to fill those questions that openssl is asking me using the variables in the script that is lunching openssl
ok... so what you want to open an interactive shell. have a look at this: pymotw.com/2/subprocess
I have found some solution for the openssl. There is a man openssl that can fill up the required questions. But the main questions is how to interact with some shell that show questions that need to be filled with some input from the user. And i want to autmatcly fill up that questions with some variables that i will have in the script. The same for example with ssh-keygen command, when you are prompted with questions, the user need to fill this questions. path where to store the keys, passwords names etc.

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.